Reported July 2025
Snowflakesimulation

Simulate a Queued Multi-Rule Rate Limiter

Reported by candidates from Snowflake's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Snowflake OA. Under 2s to a working solution.
Founder's read

Snowflake reportedly put a queued multi-rule rate limiter in front of candidates in July 2025, and the sample cases look friendlier than the real thing. It's a FIFO simulation with up to 10 rules, each tracking successful handler starts in a rolling window. Most people nail example 1 and then trip on the interaction between rules and failed requests. If your OA invite says Snowflake, expect to write this cleanly under pressure. StealthCoder is the safety net on the live OA if your mind goes blank on the per-rule queue bookkeeping, but the logic below is small enough to hold in your head.

The problem

Simulate a serialized, thread-safe rate limiter over a finite FIFO request stream.
Each request is [arrivalTime,successFlag]. Requests arrive in nondecreasing time order and join one FIFO queue; equal-time requests preserve input order. A successFlag of 1 means its handler succeeds, and 0 means the handler throws.
Each rule is [limit,window]. For this exercise, assume a rule permits at most limit successful handler executions in the rolling half-open interval (time - window,time]. Therefore, a success processed at time s frees its slot exactly at s + window. Every rule must have capacity before the request at the front of the queue may invoke its handler.
Handlers run atomically in FIFO order. A failed handler still waits for capacity before it runs, but after it throws it consumes no slot in any rule. A successful handler consumes one slot in every rule.
Return each request's actual handler-start time in original input order.

Function
simulateRateLimiter(requests: int[][], rules: int[][]) → long[]

Examples
Example 1
requests = [[0,1],[1,1],[2,1],[3,1],[4,1]]
rules = [[2,5]]
return = [0,1,5,6,10]
The first two successes occupy both slots. The third waits until time 5, when the success at time 0 expires. FIFO serialization then makes the fourth wait until 6 and the fifth until 10.
Example 2
requests = [[0,1],[1,0],[2,1],[3,1]]
rules = [[2,10]]
return = [0,1,2,10]
The handler at time 1 throws and consumes no slot. The successful requests at 0 and 2 fill the rule, so the last request waits until the first slot frees at time 10.
Example 3
requests = [[0,1],[1,1],[2,1],[3,1]]
rules = [[2,5],[3,10]]
return = [0,1,5,10]
The 5-second rule delays the third request to time 5. At that point the 10-second rule contains three successes, so the fourth request cannot run at time 6; it waits until time 10.

Constraints
0 <= requests.length <= 200000
Every request is [arrivalTime,successFlag], arrival times are nondecreasing nonnegative integers, and successFlag is 0 or 1.
1 <= rules.length <= 10
Every rule is [limit,window] with 1 <= limit <= 200000 and 1 <= window <= 10^9.
Every returned processing time fits in a signed 64-bit integer.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that each request's start time is the max of its arrival time, the previous request's start time (FIFO serialization), and, for every rule, the time its oldest relevant success expires. Keep one deque of success start times per rule. Before starting a request at time t, pop entries with time + window <= t. If a deque still holds limit entries, the earliest allowed time is the front plus window. Take the max across rules, then re-evict at the new time. The pitfall is the half-open interval: a slot frees exactly at s + window, not after. Another is forgetting that failures wait for capacity but record nothing. Also don't compute rules independently and stop: after waiting for one rule, another may still be full, so loop or take the max and re-check. Use 64-bit ints. Complexity is O(n * rules) amortized. If you blank mid-assessment, StealthCoder can supply this structure live.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Simulate a Queued Multi-Rule 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Snowflake's OA.

Snowflake reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Simulate a Queued Multi-Rule Rate Limiter FAQ

What's the core trick in the Snowflake rate limiter problem?+

Process requests in order and keep a deque of success times per rule. A request starts at the max of its arrival, the previous start time, and the earliest expiry across any full rule. Evict entries where time + window <= current time. That's the whole simulation.

How hard is this really?+

Medium. The idea is simple, but the details bite: half-open windows, failed handlers that wait but consume nothing, and multiple rules that must all have capacity. Off-by-one on expiry is the most common bug. Write the examples as tests before submitting.

Why does example 3 give 10 for the last request?+

The 5-second rule frees a slot at time 5, so the third request runs then. At time 6 the 10-second rule already holds three successes (0, 1, 5) and its limit is 3. The first expires at 10, so the fourth request waits until 10.

Do failed requests affect later ones?+

Yes, in two ways. They must wait for capacity like any request, and they still occupy the serialized FIFO slot, so later requests can't start before them. But they add nothing to any rule's deque, so they never reduce capacity for others.

How do I prepare for this in 48 hours?+

Practice sliding window and queue-based simulation. Code a single-rule limiter first, then extend to multiple rules with a max across them. Test with equal arrival times, window boundaries, all failures, and large windows near 10^9. Use long for times to avoid overflow.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Snowflake.

OA at Snowflake?
Invisible during screen share
Get it