Skip to content

#933 - Number of Recent Calls

EasyQueue
Open on LeetCode

Implement a RecentCounter class that counts the number of recent requests within a certain time frame.

  • RecentCounter() – initializes the counter with zero requests.
  • ping(t: number) – adds a new request at time t (strictly increasing) and returns the number of requests that have happened in the inclusive range [t - 3000, t].
InputOutput
OperationsOutput
ping(1), ping(100), ping(3001), ping(3002)[1, 2, 3, 3]

Released under the MIT License.