Description

Implement RecentCounter to count the number of recent requests within a time frame. The ping(t) method returns the number of pings in the inclusive range [t - 3000, t].

Examples

Input:pings = [1,100,3001,3002]
Output:[1,2,3,3]
Explanation:

Counts in [t-3000,t].

Input:pings = [1]
Output:[1]
Explanation:

A single ping at time 1 has one request in the [1-3000, 1] window, so the count is 1.

Input:pings = [1,500,1000,2000,4500,5000]
Output:[1,2,3,4,2,3]
Explanation:

At t=1: count [1] = 1. At t=500: count [1,500] = 2. At t=1000: count [1,500,1000] = 3. At t=2000: count [1,500,1000,2000] = 4. At t=4500: only [2000,4500] are within [1500,4500] = 2. At t=5000: [2000,4500,5000] are within [2000,5000] = 3.

Constraints

  • 1 ≤ calls ≤ 10⁴

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!