FastPrepAPI Shield with Two Rolling Limits
Problems/API Shield with Two Rolling Limits

API Shield with Two Rolling Limits

Graviton logoGraviton● HardFULLTIMEOA

Updated Dec 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported from a Graviton online assessment for a full-time quantitative researcher role that the candidate had applied to online. The assessment was half coding and half probability questions; this is one of the coding tasks. The task is about sending requests under rate limits: requests wait in a first-in-first-out buffer of fixed size, and two sliding windows each cap how many requests may be sent. The function takes the number of requests, both window lengths with their caps, the buffer size and the arrival times, and returns the fewest requests that must be dropped. The candidate did not pass.

The report does not give the order of events inside one second, input limits or examples; that order (arrivals, then sends, then drops beyond b), the limits and all examples are ours.

Our version is about 85% the same as the reported question.

Requests arrive at integer seconds. There are n requests, and t[i] is the arrival second of request i. A first-in-first-out (FIFO) buffer holds up to b waiting requests and drops the newest arrivals that exceed its capacity at a second.

Sends must satisfy both limits: at most m1 sends in any w1-second window, and at most m2 sends in any w2-second window. A w-second window is any w consecutive seconds.

Inside one second s, events happen in this order:

  1. All requests that arrive at second s join the back of the buffer.
  2. Requests are sent from the front of the buffer. Any number of them may be sent at second s, as long as, counting them, seconds s - w1 + 1 to s hold at most m1 sends and seconds s - w2 + 1 to s hold at most m2 sends.
  3. If more than b requests are still waiting, the newest ones are dropped until b remain.

Sending continues after the last arrival until the buffer is empty. Minimize the number of dropped requests, and return that smallest number.

Function

minDropped(n: int, w1: int, m1: int, w2: int, m2: int, b: int, t: int[]) → int

Examples

Example 1

n = 9w1 = 1m1 = 2w2 = 3m2 = 3b = 2t = [0,0,0,0,1,1,2,3,3]return = 2

Limit 1 allows at most 2 sends in any 1 second, and limit 2 allows at most 3 sends in any 3 consecutive seconds.

  • Second 0: 4 requests arrive. 2 are sent (limit 1). 2 wait, which fits in the buffer (b = 2).
  • Second 1: 2 arrive, so 4 are waiting. The 3-second window ending at second 1 already holds 2 sends, so limit 2 allows only 1 more. 3 still wait, so the newest one is dropped.
  • Second 2: 1 arrives, so 3 are waiting. The window ending at second 2 already holds 3 sends, so nothing is sent, and the newest request (the one that just arrived) is dropped.
  • Second 3: 2 arrive, so 4 are waiting. The window ending at second 3 holds only 1 send, so 2 are sent and 2 wait.

No more requests arrive, so the 2 waiting requests are sent later and nothing else is dropped. No other way of sending drops fewer than 2 requests.

Example 2

n = 6w1 = 1m1 = 2w2 = 4m2 = 3b = 0t = [1,1,1,2,2,5]return = 2

With b = 0 nothing may wait, so a request is kept only if it is sent in the second it arrives.

  • Second 1: 3 requests arrive. Limit 1 allows 2 sends in this second, so 2 are sent and the newest is dropped.
  • Second 2: 2 arrive. The 4-second window ending at second 2 already holds 2 sends, so limit 2 allows 1 more. 1 is sent and 1 is dropped.
  • Second 5: 1 arrives. The 4-second window ending at second 5 covers seconds 2 to 5 and holds 1 send, so it is sent.

2 requests are dropped.

Example 3

n = 4w1 = 1000000000m1 = 2w2 = 1m2 = 1b = 1t = [0,0,0,5]return = 1

Limit 1 allows only 2 sends in any 10^9 consecutive seconds, and limit 2 allows 1 send per second.

  • Second 0: 3 requests arrive. 1 is sent and 2 wait, which is more than b = 1, so the newest is dropped.
  • Second 1: the waiting request is sent. That is the second send in the long window.
  • Second 5: 1 arrives. The long window already holds 2 sends, so it waits. It fits in the buffer, and it is sent at second 10^9, when the send from second 0 leaves the window.

1 request is dropped.

Constraints

  • 1 <= n <= 1000
  • t.length == n
  • 0 <= t[i] <= 10^9
  • t is sorted in non-decreasing order.
  • 1 <= w1, w2 <= 10^9
  • 1 <= m1, m2 <= 1000
  • 0 <= b <= 1000

More Graviton Online Assessment questions

  • Magic Number Range CounterOA · Seen Dec 2026

Similar questions at other companies

  • Incident MonitorStripe · OAStripe interview questions
  • Per-User Sliding-Window Rate LimiterPayPal · OAPayPal interview questions
  • Per-Client Sliding-Window Rate LimiterGeneral Motors · OA
  • Key-Value Store GET and PUT QPSDatabricks · PHONE SCREENDatabricks interview questions
  • Team-Preferred Stable MatchingBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Three-Stage Labeling Workforce SimulationScale AI · PHONE SCREENScale AI interview questions
  • Sliding-Window API Rate LimiterPatreon · PHONE SCREENPatreon interview questions
  • Sliding-Window Rate LimiterSnowflake · ONSITE INTERVIEWSnowflake interview questions
  • Rate Limiter Sliding Window With Per-Entity LimitsRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
  • Metric Counter with a Fake ClockSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
See Graviton hiring insights
Saved
class Solution {
    public int minDropped(int n, int w1, int m1, int w2, int m2, int b, int[] t) {
        // Write your code here.
    }
}
Checking account…