Problem 27 of 75

Number of Recent Calls

EasyNot solved yetInterview me on this
Before you code · which pattern fits?

The problem

Implement a RecentCounter class that counts recent requests within a 3000 millisecond window. ping(t) records a request at time t (strictly increasing) and returns the number of requests in [t - 3000, t].

ping(1)=1, ping(100)=2, ping(3001)=3, ping(3002)=3

Your solution runs against 1 unit tests, including edge and large-value cases.

Loading...

Test console · 1 unit tests

Submit your code to run it against all 1 unit tests. Results appear here.

JavaScript, TypeScript & Python run sandboxed in your browser; other languages run on the execution server. Your code is saved locally as you type.

Hint

Reference solution

Video explanation

Number of Recent Calls, explainedNick White