Code Room
CodingMediumcod-g965
Subject Cache storageLevel Mid–Senior~25 minCommon in Storage & CDN · Networking & APIs · Algorithms & data structures interviewsIndustries Technology, Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.