Code Room
CodingMediumcod-g997
Subject SecurityLevel Mid–Senior~18 minCommon in Security · Networking & APIs · Algorithms & data structures interviewsIndustries Software development

Question

Implement a sliding-window rate-limiter check for an API gateway. Given a list of request `timestamps` (integers) already recorded for a user, a `window` length, a `limit` (max allowed requests within the window), and the current time `now`, decide whether a NEW request at `now` is allowed. A request counts as in-window if its timestamp is strictly greater than `now - window`. The new request is allowed only if the number of in-window prior requests is strictly less than `limit`. Return True if allowed.

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