Token bucket continuous refill

Write codeMedium30 minStripe style

Your task

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.

Examples

token_bucket(requests: list[int], capacity: int, refill_per_sec: float) -> list[bool]
Example 1
Inputtoken_bucket([0, 0, 0, 1], 2, 1)
Output[True, True, False, True]