Number of Recent Calls Problem

Number of Recent Calls Problem — ExecCode Easy DSA Practice

Solve the Number of Recent Calls problem on ExecCode. Free online easy DSA practice in Design. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Implement the RecentCounter class which counts the number of recent requests within a past 3000 ms time frame. ping(t) adds a request at time t and returns how many requests have happened in the inclusive range [t - 3000, t].

Examples

Input {"pings": [1, 100, 3001, 3002, 7000]}; Output [1, 2, 3, 3, 1]. Input {"pings": [1, 100, 3001]}; Output [1, 2, 3]. Input {"pings": [1, 3001, 3002, 6001]}; Output [1, 2, 2, 3]

Constraints

1 ≤ t ≤ 10⁹ Each ping uses a strictly larger t. At most 10⁴ calls to ping.

Practice Number of Recent Calls free on ExecCode. Browse DSA problems, topic map, and placement guides.