Code Room
CodingMediumcod-g225
Subject Rate limiter designLevel Mid–Senior~30 minCommon in Networking & APIs · Algorithms & data structures interviewsIndustries Software development

Question

Implement a sliding-window-log rate limiter. Given a list of integer request timestamps (non-decreasing seconds), a 'limit', and a 'window' size in seconds, a request at time t is allowed if the number of previously-allowed requests with timestamp strictly greater than t-window (i.e. within the last 'window' seconds, half-open) is less than 'limit'; an allowed request is recorded. Rejected requests are not recorded. Return a list of booleans aligned to the input. Empty input returns an empty list.

Implement
sliding_window_log(timestamps: list[int], limit: int, window: int) → list[bool]
Examples
in[[1,2,3],2,10]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.

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.