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

Question

Implement a sliding-window-log rate limiter allowing at most `max_req` requests within any `window`-length time window. Given a chronologically ordered list of request `timestamps`, a request at time `ts` is allowed if, after dropping all logged timestamps `<= ts - window`, fewer than `max_req` remain; if allowed, its timestamp is logged. Return a list of booleans. Timestamps are non-decreasing.

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