← All problems
Number of Recent Calls
Implement a RecentCounter class: ping(t) records a call at time t (milliseconds, strictly increasing) and returns the number of calls in the inclusive window [t - 3000, t]. Design ping to be efficient even after many calls — you should not rescan the entire history each time.
Complexity
Amortized O(1) per ping, space O(n) for the window.
Common pitfalls
- Rescanning all stored times per ping for O(n^2) total.
- Using < vs <= on the window boundary [t-3000, t] (inclusive on both ends).
- Using a list with pop(0), which is O(n) per pop — use collections.deque.
Your solution
Log in to save your code and track progress.