Number of Recent Calls

Easy

Topics
QueueDesignData Stream

Implement RecentCounter that counts recent requests within a time window. Implement ping(t) which records a request at time t (in milliseconds) and returns the number of requests that happened in the inclusive range [t - 3000, t]. Every call to ping uses a strictly larger t than the previous call.

Example 1

Input:  operations = ["RecentCounter","ping","ping","ping","ping"], values = [[],[1],[100],[3001],[3002]]
Output: [null,1,2,3,3]

Constraints

  • 1 <= t <= 10^9
  • Each call to ping uses a strictly increasing t.
  • At most 10^4 calls to ping.
Run ⌘' · Submit ⌘⏎