FastPrepSimulate a Queued Multi-Rule Rate Limiter
Problems/Simulate a Queued Multi-Rule Rate Limiter

Simulate a Queued Multi-Rule Rate Limiter

Snowflake logoSnowflake● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Snowflake phone screen. The report describes one rate-limit rule and then several, queued requests, counting only requests that the handler accepts, and ordering problems. It does not give the rule layout, where the time boundary falls, a finite input form or the output. Our simulation is about 84% the same as the reported question.

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.

More Snowflake Phone Screen questions

  • Connect Four from the Last MovePHONE SCREEN · Seen Nov 2026
  • Minimum Edits to a Perfect Binary TreePHONE SCREEN · Seen Nov 2026
  • Configurable Per-Client Token BucketsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Find Valid SET Card TriplesOA · PHONE SCREEN · Seen Nov 2026
  • Minimum Index Distance Between Person and CakeOA · PHONE SCREEN · Seen Nov 2026
  • Minimum N-ary Tree Depth DeletionsOA · PHONE SCREEN · Seen Nov 2026
  • Sum of Binary Tree Boundary NodesOA · PHONE SCREEN · Seen Nov 2026
  • Greedy Person-Cake Matching DistancePHONE SCREEN · Seen Nov 2026
  • Tree Height After Child PromotionPHONE SCREEN · Seen Oct 2026
  • Minimum StackPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
  • Implement a FIFO QueueByteDance · PHONE SCREENByteDance interview questions
  • Concurrent Discounted Card PurchasesBrex · PHONE SCREEN
  • High-Card Pot GameAffirm · PHONE SCREENAffirm interview questions
  • Stateful Paginated Fetch NLyft · PHONE SCREENLyft interview questions
  • Music Player Operation SequenceAtlassian · PHONE SCREENAtlassian interview questions
  • Schedule Buffered Video PlaybackNuro · PHONE SCREENNuro interview questions
  • Machine Message RouterOpenAI · PHONE SCREENOpenAI interview questions
  • Bus Station Seat AllotmentInMobi · PHONE SCREENInMobi interview questions
  • FIFO FizzBuzz Market MatchingGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions

Snowflake interview experiences

  • Snowflake AI Coding Interview, Experienced Hires: 3 Experiences
All Snowflake interview questionsSee Snowflake hiring insights
Saved
class Solution {
    public long[] simulateRateLimiter(int[][] requests, int[][] rules) {
        // Write your code here.
    }
}
Checking account…