← 返回 roblox 的题目列表Design a Rate Limiter
类型:online_judge
Design a rate limiter: You need to design a system that can record API access counts and limit the number of requests within a certain time window using a deque data structure. Implement a function shouldAllow(timestamp: int) -> bool that determines whether a request is allowed at the given time timestamp. Use a window period of 60 seconds and allow no more than 100 requests within the same window.
Input Description:
timestamp: an integer representing the current timestamp in seconds, 1 <= timestamp <= 10^9.
You can assume the timestamps are strictly increasing.
Output Description:
bool: a boolean indicating whether this request is allowed.
Example:
Input:
[1, 1, 1, 3, 3, 3, 3, 61]
Output:
[true, true, true, true, true, true, false, true]
Data Scale:
The number of requests can be up to 10^6.
Example
Input
1
1
1
3
3
3
3
61