Skip to interview prep
Apexed
Problem list117 / 143

117. Apply a Sliding Request Limit

MediumAPI quotas

Requests are [account, timestamp] pairs in nondecreasing timestamp order. Each account can have at most limit accepted requests in any window of width time units.

For a request at t, count earlier accepted requests from its account at times in (t - width, t]. Accept only if that count is below limit. Equal timestamps follow input order and rejected requests never count. Return an array of Booleans.

Example 1

Input: requests = [["a",0],["a",4],["a",5],["a",5],["a",9],["a",10]], width = 5, limit = 1
Output: [true,false,true,false,false,true]

Example 2

Input: requests = [["a",1],["b",1],["b",1],["a",2]], width = 10, limit = 1
Output: [true,true,false,false]

Constraints

  • At most 100,000 requests. Times are integers in [0, 10⁹].
  • 1 ≤ width ≤ 10⁹ and 0 ≤ limit ≤ 100,000.

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 5 hidden and sample tests.

Code runs in an isolated browser sandbox. Progress and submissions are saved on this device.

Apply a Sliding Request Limit — coding interview practice — Apexed