Number of Recent Calls

Design a counter that returns how many calls happened in the last 3000 milliseconds each time a new call arrives. Pattern focus: Circular Queue (Ring Buffer). Remove stale timestamps from the front and keep only the active time window.

Input Format

t = array of call timestamps in milliseconds

Output Format

count of calls in the last 3000 milliseconds after each timestamp

Constraints

  • 1 <= input size <= 10^5
  • -10^9 <= numeric values <= 10^9
  • t must satisfy the format described in inputFormat.

Examples

Example 1:

Input:

t = [1,100,3001,3002]

Output:

[1,2,3,3]

Explanation:

Each ping counts how many timestamps fall within the last 3000 ms.

Example 2:

Input:

t = [1,2,3,4,3000]

Output:

[1,2,3,4,5]

Explanation:

All calls remain in the active 3000 ms window.

Loading...
Number of Recent Calls - Queue Deque DSA Problem