Code RoomLeaky bucket rate limiter
MediumPrep Room Coding #318

Leaky bucket rate limiter

CodingNetworking & APIsMid–Senior~22 min

Simulate a leaky-bucket rate limiter. The bucket has an integer 'capacity' and leaks 'leak_rate' units per second (continuously). Process 'events', a list of [time, amount] with non-decreasing integer times. Before each event, leak (time - last_time) * leak_rate units (the level never drops below 0). An event is accepted if level + amount <= capacity (then add amount); otherwise rejected (level unchanged). Return a list of booleans, one per event. Times start at 0.

Implement
leaky_bucket(capacity: int, leak_rate: int, events: list[list[int]]) → list[bool]
Examples
in[10,1,[[0,5],[0,5],[0,1]]]out[true,true,false]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 22 min
InputExpectedGot
[10,1,[[0,5],[0,5],[0,1]]][true,true,false]not run yetsample