The Number of Recent Calls problem asks you to design a class that accepts timestamp-ordered ping(t) calls and returns the count of pings in the last 3000 milliseconds (inclusive) — i.e., in the range [t-3000, t]. This Number of Recent Calls coding problem is a classic sliding window queue design problem.
Databricks, Uber, Microsoft, Meta, Amazon, Google, and Bloomberg ask this as a system design + data structures warm-up. It tests whether candidates know that a queue (deque) is the right data structure for a sliding time window. The data stream, design, and queue interview pattern is directly applied.
Queue with front-pruning. Maintain a queue of all ping timestamps. For each new ping t: add t to the back. Remove all timestamps from the front that are less than t - 3000. Return the current queue size.
Pings: [1, 100, 3001, 3002].
[t-3000, t] (inclusive on both ends).Sliding window data stream problems always use a deque or queue with front-removal. The pattern: (1) add new element to back, (2) remove expired elements from front, (3) return size. This applies to moving averages, recent activity counts, and real-time monitoring. Practice designing Rate Limiter, Moving Average, and Request Counter — they all use this same queue-with-expiry template.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Moving Average from Data Stream | Easy | Solve | |
| Design Hit Counter | Medium | Solve | |
| First Unique Number | Medium | Solve | |
| Design Front Middle Back Queue | Medium | Solve | |
| Find Consecutive Integers from a Data Stream | Medium | Solve |