Code RoomSliding window limiter
MediumPrep Room Coding #1528

Sliding window limiter

CodingStorage & CDNNetworking & APIsMid–Senior~25 min

Implement a sliding-window rate limiter. A client may make at most `limit` requests within any window of `window` seconds. Given a list of request timestamps (non-decreasing non-negative integers), decide each request in order: a request at time t is ALLOWED if, counting it, the number of allowed requests with timestamp > t - window (i.e. strictly within the trailing window) is at most `limit`; otherwise it is DENIED and is NOT recorded. Only allowed requests count toward future windows. Return a list of booleans, True for allowed and False for denied. limit is a positive integer; window is a positive integer.

Implement
sliding_window_limiter(limit: int, window: int, timestamps: list[int]) → list[bool]
Examples
in[2,10,[0,1,5,11]]out[true,true,false,true]
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
[2,10,[0,1,5,11]][true,true,false,true]not run yetsample