API Rate Limiter
API Rate Limiter
Fixed-window rate limiter. Requests arrive at integer timestamps. The window for timestamp t is floor(t / W). Allow a request if its window has seen at most K requests so far (including itself), otherwise BLOCK. Return the decision (ALLOW/BLOCK) for each request in order.
Approach
Given a stream of request timestamps and a fixed-window rate limit, output ALLOW or BLOCK for each request in order. At most k requests are allowed within each fixed window of w seconds, where a timestamp t belongs to window (t // w) — windows are aligned to multiples of w (NOT a sliding window). Args: solve(nums, k, w).
Input
Output
More Backend problems
Browse all coding problems →Press Run to test your custom input, or Submit to judge against all test cases.
Sign in to continue
Create a free account to run code, submit solutions and track progress.
- Free forever — no credit card
- 10+ languages with live execution
- Points, streaks & leaderboards