Sliding-Window Rate Limiter
Reported by candidates from Snowflake's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Snowflake sliding-window rate limiter, reported in September 2026, looks friendly until the boundary bites you. The window is half-open, so a request at time t - windowSeconds no longer counts, and plenty of first attempts get that wrong. If you have this OA coming up in the next day or two, the pattern is a queue-backed sliding window, and the logic fits in about fifteen lines. The hard part is the details: rejected requests don't take a slot, and equal timestamps go in input order. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but you should know the shape of this before you open it.
The problem
Process request timestamps requestTimes in their given order. For every request at time t, allow it only when fewer than limit previously allowed requests have timestamps in the half-open interval (t - windowSeconds, t]. An allowed request consumes one slot in the window. A rejected request is dropped immediately and does not consume a slot. Timestamps are nondecreasing. Requests with the same timestamp are processed in input order. Return one boolean per request, where true means allowed and false means rejected. Function acceptRequests(requestTimes: int[], limit: int, windowSeconds: int) → boolean[] Examples Example 1 requestTimes = [1,2,3,4,7] limit = 3 windowSeconds = 5 return = [true,true,true,false,true] The request at time 4 is rejected because three allowed requests remain in its window. At time 7, the request at time 2 is excluded by the open left boundary, so one slot is available. Example 2 requestTimes = [10,10,10,10] limit = 2 windowSeconds = 3 return = [true,true,false,false] Equal-time requests are processed in order. The first two consume the available slots; rejected requests do not change the window. Example 3 requestTimes = [] limit = 1 windowSeconds = 1 return = [] An empty request stream produces an empty decision array. Constraints 0 <= requestTimes.length <= 200000 0 <= requestTimes[i] <= 10^9 requestTimes is nondecreasing. 1 <= limit <= 200000 1 <= windowSeconds <= 10^9
Reported by candidates. Source: FastPrep
Pattern and pitfall
Keep a queue of timestamps for allowed requests only. For each request at time t, pop from the front while the front is less than or equal to t - windowSeconds. That inequality is the trap. The interval is (t - windowSeconds, t], so a timestamp exactly at t - windowSeconds is expired. Then if the queue size is below limit, push t and output true. Otherwise output false and push nothing. Each timestamp enters and leaves once, so it's O(n) total, which matters with 200000 requests. Common pitfalls: using less-than instead of less-than-or-equal when evicting, pushing rejected requests into the queue, and scanning the whole window per request, which goes quadratic. Example 1 at time 7 is a good self-test, since time 2 must be evicted. If you freeze on the boundary during the live OA, StealthCoder is the hedge that gets you the correct eviction condition fast.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Sliding-Window Rate Limiter cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Snowflake's OA.
Snowflake reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Sliding-Window Rate Limiter FAQ
What's the trick in the Snowflake sliding-window rate limiter?+
Store only allowed timestamps in a queue. Before each decision, evict anything at or before t - windowSeconds. Allow the request if the queue size is under limit, then push t. Rejected requests never get pushed. That's the whole solution, and it runs in linear time.
Why does the half-open interval matter so much?+
The window is (t - windowSeconds, t], so the left edge is excluded. A timestamp exactly equal to t - windowSeconds must be evicted. Using a strict less-than instead leaves it in and flips answers on boundary cases like time 7 in Example 1.
How hard is this problem really?+
Easy to medium. The algorithm is a standard queue or two-pointer window. Difficulty comes from the boundary condition and from not counting rejected requests. With inputs up to 200000, you also need to avoid rescanning the window for every request.
Do I need a deque or can I use two pointers?+
Either works. Since timestamps are nondecreasing and only allowed ones count, you can keep an array of allowed times with a head index. Advance the head while the value is at or before t - windowSeconds. Size is the array length minus head.
How do I prepare for this in 48 hours?+
Write it once from scratch and test the three examples, especially equal timestamps and the empty input. Then try a case where the limit is 1 and times sit exactly windowSeconds apart. If you can pass those without editing the eviction line, you're ready.