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
DAILY PROBLEM OF THE DAY+50 XP • Daily Streak
Solve today's challenge or tackle one of the 3 Super Hard challenges for +150 XP.
MediumSystem Design•Acceptance: 54.2%
Token Bucket Rate Limiter (API Gateway)
Targeted in FAANG & Tech OA:UberSwiggyAmazonGoogle
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.
Recruiter Fast-Track ReferralVerified Candidate
Direct pipeline to Google, Amazon, Microsoft, Swiggy, & Uber recruiters
Top DevScore profiles bypass resume screening filters. Every verified problem solve writes authentic proof-of-work to your profile and dispatches you directly into employer inboxes on RoleNest.
Explore 5,000+ Direct ATS Openings on RoleNest ↗✓ Direct Referral Active
Language:
Ready to test. Click Run Code or Submit Solution to run test cases in isolated browser sandbox.