← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Design and implement a sliding-window rate limiter that, for each unique user (or client), allows at most max_requests in any rolling window_seconds interval. The system must expose a single method isAllowed(user_id: str) -> bool that returns True if the request is within the limit and False otherwise. Internally maintain a per-user deque (or list) of Unix-second timestamps. On every call, first discard every timestamp older than now - window_seconds, then append the current timestamp if the remaining count is below max_requests. All operations must be thread-safe and run in O(1) average time per request. The solution should handle millions of users and bursts of traffic without memory leaks.