Sliding-Window Rate Limiter
Updated
Problem statement
Given n, t, and a nondecreasing array timestamps, process the requests in order and return whether each one is allowed. The rate limiter allows at most n requests in any window of t integer seconds.
For a request at time x, the window is the inclusive range [x - t + 1, x]. Allow the request exactly when fewer than n previously allowed requests have timestamps in that window. A rejected request is not kept and does not affect later decisions.
Function
rateLimitRequests(n: int, t: int, timestamps: int[]) → boolean[]Examples
Example 1
n = 3t = 5timestamps = [1,1,2,3,8]return = [true,true,true,false,true]The first three requests fill the window, so the request at time 3 is rejected. By time 8, all earlier allowed requests have left the window.
Example 2
n = 1t = 3timestamps = [1,2,4,4]return = [true,false,true,false]The rejected request at time 2 is not counted. The request at time 1 expires before time 4, so the first time-4 request is allowed.
Example 3
n = 2t = 2timestamps = [5,5,6,7]return = [true,true,false,true]Both time-5 requests are active at time 6, so that request is rejected. They expire before time 7.
Constraints
1 <= n <= 100000.1 <= t <= 1000000000.1 <= timestamps.length <= 100000.0 <= timestamps[i] <= 1000000000.timestampsis nondecreasing.
More Bloomberg LP Phone Screen questions
- Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
- Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
- Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Sliding-Window API Rate LimiterPatreon · PHONE SCREEN · ONSITE INTERVIEWPatreon interview questions
- Rate Limiter Sliding Window With Per-Entity LimitsRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
- Completions API Rate LimiterCursor · PHONE SCREENCursor interview questions
- Key-Value Store GET and PUT QPSDatabricks · PHONE SCREENDatabricks interview questions
- Sliding-Window Rate LimiterSnowflake · ONSITE INTERVIEWSnowflake interview questions
- Per-Client Sliding-Window Rate LimiterGeneral Motors · OA
- Metric Counter with a Fake ClockSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
- Per-Client Sliding-Window Rate LimiterNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
- API Shield with Two Rolling LimitsGraviton · OA
- Per-User Sliding-Window Rate LimiterPayPal · OAPayPal interview questions