Loading
Loading
A rate monitor receives request timestamps in strictly increasing order. After each one it reports how many requests arrived within the preceding 3000 milliseconds, inclusive of both endpoints.
Return the count reported after each timestamp.
timestamps = [1, 100, 3001, 3002]t=1window [-2999, 1] → 1t=100window [-2900, 100] → 2t=3001window [1, 3001] → 3t=3002window [2, 3002] → 1 expires → 3[1, 2, 3, 3]Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(n) time · O(w) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
Example 2
Example 3
3002 - 1 = 3001 milliseconds, just outside the window, so timestamp 1 has expired.