Token Bucket Count
Hard · Concurrency
A simple limiter: capacity cap tokens, start full. Each request costs 1 token. Tokens refill by refill each tick, capped at cap. Given requests as a list of ticks (non-decreasing), return how many requests are allowed.
Write Allowed(cap, refill, requests) where requests[i] is the tick of request i. Refill happens at the beginning of each new tick, based on elapsed ticks since the previous request (or 0).
Next: First Error Wins