← 返回 atlassian 的题目列表Implement a Rate Limiter
类型:online_judge
Implement a rate limiter. The limiter should restrict the number of requests allowed per minute. Any requests beyond this count should be denied. Design a class interface, including initialization method and the following functionalities:
request(int timestamp): Accepts the current request timestamp (in seconds) and checks if the current request is allowed.
boolean allow(): Returns whether the current request can be processed.
Assume at most 1000 requests might be processed at any point in time. The timestamps given are in increasing order.
Example:
Input: Initialize to allow at most 5 requests.
request(0), request(10), request(20), request(30), request(40), request(50)
Output: true, true, true, true, true, false
Constraints:
The implementation should be thread-safe
Internal state management should be memory efficient
Example
Input
5
0 10 20 30 40 50