Code RoomToken bucket continuous refill
MediumPrep Room Coding #1235

Token bucket continuous refill

CodingNetworking & APIsMid–Senior~30 min

Implement a token-bucket rate limiter. The bucket has a maximum capacity and refills at a constant rate of `refill_per_sec` tokens per second (continuous, fractional accumulation allowed, capped at capacity). The bucket starts full. Given a non-decreasing list of integer-second request times, each request needs exactly 1 token: if at least 1 token is available it is allowed and 1 token is consumed; otherwise it is rejected. Return the list of booleans for each request.

Implement
token_bucket(requests: list[int], capacity: int, refill_per_sec: float) → list[bool]
Examples
in[[0,0,0,1],2,1]out[true,true,false,true]
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.

0:00 of about 30 min
InputExpectedGot
[[0,0,0,1],2,1][true,true,false,true]not run yetsample