Code Room
CodingMediumcod-g874
Subject Rate limiter designLevel Mid–Senior~25 minCommon in Networking & APIs interviewsIndustries Software development, Technology

Question

Simulate a token-bucket rate limiter. The bucket starts full with `capacity` tokens and refills at `refill_rate` tokens per time unit, never exceeding `capacity`. Given a chronologically ordered list of `[timestamp, cost]` requests, each request first refills the bucket based on elapsed time since the previous request, then is allowed (consuming `cost` tokens) only if at least `cost` tokens are available. Return a list of booleans for the requests. Timestamps are non-decreasing.

Implement
token_bucket(capacity: int, refill_rate: int, requests: list[list]) → list[bool]
Examples
in[2,1,[[0,1],[0,1],[0,1]]]out[true,true,false]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.