Token Bucket Admission
Requests are sorted [timestamp_seconds, token_cost] pairs. Implement token_bucket_admission(requests, capacity, refill_per_second) and return one boolean per request. Begin with a full bucket at the first timestamp. Before each request, refill by elapsed seconds times refill_per_second, capped at capacity. Allow and deduct cost only if enough tokens remain; rejected requests consume none. Numeric inputs are nonnegative and timestamps are nondecreasing. Floating-point comparisons may be used directly.
Examples
A guided view of the published example, not a trace of your code.
[[[0,3],[0,3],[2,2]],5,1][true,false,true]Start with the input values shown in this example.
Input: requests = [[0,3],[0,3],[2,2]], capacity = 5, refill_per_second = 1
Output: [true,false,true]
Explanation: burst and refill
Input: requests = [[10,2],[11,2]], capacity = 2, refill_per_second = 2
Output: [true,true]
Explanation: full refill
Hint 1
The bucket starts full at the first event time.
Hint 2
A denied request leaves the balance unchanged.