Code RoomSliding window rate limiter
MediumPrep Room Coding #288

Sliding window rate limiter

CodingSecurityNetworking & APIsMid–Senior~25 min

Implement a sliding-window rate limiter. Given a chronologically-ordered list of events [key, timestamp], a window size in seconds, and a 'limit' (max allowed events per key within any window), return the list of booleans indicating, for each event in order, whether it is ALLOWED. An event is allowed if the count of previously-allowed events for the same key whose timestamp is strictly greater than (timestamp - window) is less than 'limit'; allowed events are recorded, rejected events are not. Timestamps are non-decreasing.

Implement
rate_limit(events: list[list], window: int, limit: int) → list[bool]
Examples
in[[["k",1],["k",2],["k",3]],10,2]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 25 min
InputExpectedGot
[[["k",1],["k",2],["k",3]],10,2][true,true,false]not run yetsample