You are coding as a Guest. Sign in with your RoleNest account to permanently track your streak, earn XP, and climb the Campus Leaderboard!
Sign In with RoleNestProblem Set
🔥Token Bucket Rate Limiter (API Gateway)Medium
MediumSystem Design•Acceptance: 54.2%
Token Bucket Rate Limiter (API Gateway)
Real-World Engineering Context
Deployed in Cloudflare WAF and Stripe API Gateways to prevent DDoS and API quota exhaustion.
Simulate an API Gateway Token Bucket rate limiter. Given `capacity`, `refillRate` (tokens per second), and an ascending list of arrival timestamps `timestamps` (seconds), return an array of booleans indicating if each request was accepted (`true`) or throttled (`false`). Bucket starts at full capacity.
Sample Test Cases
Input: [2,1,[0,0.1,0.2,1.5]]
Expected: [true,true,false,true]
Input: [1,0.5,[0,0.05]]
Expected: [true,false]
Constraints
- 1 <= capacity <= 1000
- 0.1 <= refillRate <= 100.0
- timestamps are in non-decreasing order.
Language:
Ready to test. Click Run Code or Submit Solution to run test cases in isolated browser sandbox.