Token Bucket Request Decisions
Updated
Problem statement
Simulate a token-bucket rate limiter for requests arriving at integer-second timestamps.
For this exercise, assume the bucket starts full with capacity tokens. Immediately before each request, add refillRate tokens for every whole second elapsed since the previous request, capped at capacity. A request is allowed and consumes one token when a token is available; otherwise it is rejected. Process requests in the supplied nondecreasing order and return one decision per request.
Function
allowRequests(arrivalTimes: int[], capacity: int, refillRate: int) → boolean[]Examples
Example 1
arrivalTimes = [0,0,0,1]capacity = 2refillRate = 1return = [true,true,false,true]The first two requests consume the initial tokens. The third is rejected, and one token refills before the request at time 1.
Example 2
arrivalTimes = [1,2,10]capacity = 1refillRate = 1return = [true,true,true]At least one second separates every pair of requests, so the one-token bucket refills before each request.
Constraints
1 <= arrivalTimes.length <= 10^50 <= arrivalTimes[i] <= 10^9arrivalTimesis nondecreasing.1 <= capacity, refillRate <= 10^6
More Plaid interview questions
- Validate and Resolve Evaluation ChainsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Bounded Token-Bucket Request QueueONSITE INTERVIEW · Seen Jul 2026
- Automation Pipeline, Part 1: Single WorkerPHONE SCREEN · Seen Nov 2026
- Total Pipeline Completion TimePHONE SCREEN · Seen Sep 2026
- Rule References: Validity and EligibilityPHONE SCREEN · Seen Aug 2026
- Automation Pipeline, Part 3: Stage DurationPHONE SCREEN · Seen Jul 2026
- Automation Pipeline, Part 2: Stage WorkersPHONE SCREEN · Seen Jul 2026
Similar questions at other companies
- Concurrent Buffered File LoggerDatabricks · ONSITE INTERVIEWDatabricks interview questions
- Priority Message BufferAmazon · ONSITE INTERVIEW
- Five-Minute Hit CounterGoogle · ONSITE INTERVIEWGoogle interview questions
- Sliding-Window API Rate LimiterPatreon · PHONE SCREEN · ONSITE INTERVIEWPatreon interview questions
- Sliding-Window Rate LimiterSnowflake · ONSITE INTERVIEWSnowflake interview questions
- Bounded Producer–Consumer QueueMakeMyTrip.com · ONSITE INTERVIEWMakeMyTrip.com interview questions
- Rate Limiter Sliding Window With Per-Entity LimitsRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
- First Unique ID in a StreamDoorDash · ONSITE INTERVIEWDoorDash interview questions
- Metric Counter with a Fake ClockSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
- Per-Client Sliding-Window Rate LimiterNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions