Design a token-bucket rate limiter: a structure that allows up to capacity requests at once and refills tokens at a steady rate of refillRate tokens per second.
The bucket starts full at time 0 (i.e. capacity tokens). Each allow(timestamp) call:
- Refills the bucket based on the elapsed seconds since the last refill:
tokens = min(capacity, tokens + (timestamp - lastRefill) * refillRate). Fractional tokens are allowed. - If
tokens >= 1, deduct1and returntrue(allow). - Else return
false(reject).
Timestamps are non-decreasing. refillRate and capacity may be floats.
For the auto-grader: implement tokenBucketOps(capacity, refillRate, requests) where each request is a timestamp (in seconds). Return an array of booleans matching the result of each allow().