← 返回 linkedin 的题目列表Rate Limiter with Bucket Token
类型:online_judge
Design a rate limiter with the following functionality:
request(timestamp: int) -> bool: Check if a request can be processed at the given timestamp. The rate limiter allows at most n requests in m seconds. You need to implement a lazy bucket token scheme where tokens are refilled at the arrival of the request timestamps rather than refilling every second. Assume timestamps are strictly increasing.
Requirements:
Input:
n: Integer, representing the maximum capacity of tokens in the bucket.
m: Integer, representing the window size in seconds.
Output:
bool: Return True if the request is allowed; otherwise, return False.
Implement the RateLimiter class and provide test cases for scenarios with large data volumes and memory constraints.
Example
Input
5 10
1
2
11
12
20
21