Sliding-Window Rate Limiter
Learn this problemProblem statement
Build a rate limiter that tracks API requests per client key and decides whether a client may make a request, using a sliding time window.
The limiter is configured with maxRequests and windowSeconds: a client is allowed only if it has made fewer than maxRequests recorded requests within the most recent windowSeconds. There are two operations:
hit key timestampβ record a request forkeyat integer timetimestamp.allowed key timestampβ return whetherkeyis currently allowed attimestamp, i.e. whether the number of that key's recorded hits still inside the window is strictly less thanmaxRequests. This check counts only previously recorded hits; it does not itself record a hit.
A hit at time t0 is inside the window evaluated at time t when t0 > t - windowSeconds (older hits, with t0 <= t - windowSeconds, have expired and must be ignored / cleaned up). Each key is tracked independently; an unseen key has no hits. Hits may share a timestamp, and operations are supplied in nondecreasing timestamp order.
You are given the operations as a String[] in order. Process them and return a String[] containing the result of every allowed operation, in order, as "true" or "false".
Function
runRateLimiter(maxRequests: int, windowSeconds: int, operations: String[]) β String[]Examples
Example 1
maxRequests = 3windowSeconds = 10operations = ["hit user_1 1", "hit user_1 2", "allowed user_1 3", "hit user_1 3", "allowed user_1 4", "allowed user_1 12", "allowed user_2 5"]return = ["true", "false", "true", "true"]Example 2
maxRequests = 3windowSeconds = 10operations = ["hit user_1 5", "hit user_1 5", "allowed user_1 5", "hit user_1 5", "allowed user_1 5"]return = ["true", "false"]Constraints
- Operations are
"hit key timestamp"or"allowed key timestamp"with integer timestamps. - A hit at
t0counts at evaluation timetifft0 > t - windowSeconds. allowedreturnstrueiff the key's in-window hit count is strictly less thanmaxRequests; it does not record a hit.- Each key is tracked independently; bursts at the same timestamp are allowed, and operations are in nondecreasing timestamp order.
- Return one
"true"/"false"perallowedoperation, in order.
More Stripe problems
- Group Linked Merchant RecordsPHONE SCREEN Β· Seen Jul 2026
- Invoice / Payment ReconciliationPHONE SCREEN Β· Seen Jul 2026
- Incident MonitorOA Β· Seen Jul 2026
- Merchant Fraud Risk ScoringOA Β· Seen Jul 2026
- WebSocket Load Balancer β Basic Load Balancing (Part 1)OA Β· Seen Jul 2026
- Rule-Driven Transaction Fraud DetectionOA Β· PHONE SCREEN Β· Seen Jul 2026
- Deployment Window SchedulerOA Β· Seen Jul 2026
- Directly Linked UsersOA Β· Seen Jun 2026