Design a rate limiter using the token bucket algorithm. Implement a RateLimiter class that:
capacity requests within a window time windowWrite methods:
__init__(capacity, refill_rate): capacity tokens, refill_rate tokens per secondis_allowed(tokens_needed=1): returns True if tokens are available, False otherwiserefill(): issue new tokens based on elapsed timeTrack the last refill timestamp and compute elapsed time since then.
Each request consumes tokens; refill calculates new tokens based on elapsed seconds.
No results yet
Run your code to check it against the examples, or submit to run every test.