Design a Rate Limiting System

A Rate Limiting System can allow a maximum of n requests every t seconds, using an implementation similar to the sliding window algorithm. Given two positive integers n and t, and a non-decreasing stream of integers representing the timestamps of requests, implement a data structure that can check if each request is allowed or not. Implement the RateLimiter class: RateLimiter(int n, int t) Initializes the RateLimiter object with an empty...

周六 · 2025-02-22 · 4 分钟 · Yuechen

Design a Todo List

Design a Todo List Where users can add tasks, mark them as complete, or get a list of pending tasks. Users can also add tags to tasks and can filter the tasks by certain tags. Implement the TodoList class: TodoList() Initializes the object. int addTask(int userId, String taskDescription, int dueDate, List<String> tags) Adds a task for the user with the ID userId with a due date equal to dueDate and...

周日 · 2025-02-16 · 4 分钟 · Yuechen

Design Walnut

Design a banking SMS parsing and analytics application (like Walnut) which reads all the text messages received by users and analyzes the following: The income and expenditure of a user. The average income and expenditure of all users. Text messages will be represented as a string, with words separated by ' '. The texts will be analyzed and will be considered valid if it satisfies the following criteria: It contains...

周日 · 2025-01-19 · 4 分钟 · Yuechen

"Effective Java"精读之序列化

1. 避免序列化 序列化是一种强大的功能,但也会带来许多问题,特别是在版本控制和安全性方面。应避免不必要的序列化。 总结: 如果不需要对象的序列化能力...

周日 · 2025-01-12 · 3 分钟 · Yuechen

"Effective Java"精读之并发

1. 同步访问共享可变数据 当多个线程访问共享可变数据时,必须进行同步,以防止数据竞争和一致性问题。 总结: 为了确保线程安全,必须在访问共享可变数据...

周日 · 2025-01-12 · 4 分钟 · Yuechen

"Effective Java"精读之异常

1. 仅在异常条件下使用异常 异常应仅用于表示程序中的异常情况,而不是作为正常控制流的一部分。异常的使用不当会使代码复杂且效率低下。 总结: 异常应仅...

周日 · 2025-01-12 · 4 分钟 · Yuechen

"Effective Java"精读之一般编程

1. 遵循通用命名约定 命名对于代码的可读性和可维护性至关重要,遵循常见的命名约定有助于提高代码的质量。 总结: 采用一致且具有描述性的命名方式,使代...

周日 · 2025-01-12 · 4 分钟 · Yuechen

"Effective Java"精读之方法

1. 检查参数的有效性 方法中的参数是不可忽视的,确保每个参数的有效性是非常重要的。在方法开始时进行有效性检查能够帮助及时捕捉潜在的错误。 总结: 及...

周日 · 2025-01-12 · 3 分钟 · Yuechen