Problem
Build a class RecentCounter that counts recent requests.
- ping(t) records a new request at time t (in milliseconds) and returns how many requests happened in the last 3000 milliseconds, meaning in the inclusive range [t - 3000, t], counting this one.
Every call uses a strictly larger `t` than the call before it.
Example 1
c = RecentCounter()
Example 2
- Input
- c.ping(1)
- Output
- 1
- Why
- range [-2999, 1]: just 1
Example 3
- Input
- c.ping(100)
- Output
- 2
- Why
- 1 and 100
Example 4
- Input
- c.ping(3001)
- Output
- 3
- Why
- range [1, 3001]: 1, 100, 3001
Example 5
- Input
- c.ping(3002)
- Output
- 3
- Why
- range [2, 3002]: 100, 3001, 3002
Constraints
1 <= t <= 10^9Each t is strictly larger than the previous one.At most 10^4 calls are made to ping.