17 · Queues & Deques

#933 Number of Recent Calls

Easysolve on LeetCode ↗

frequently reported atGoogleAmazon

the problem

In plain words

RecentCounter.ping(t) records a request at time t (ms) and returns how many requests happened in [t − 3000, t]. Each t is strictly larger than the previous one.

in ping(1), ping(100), ping(3001), ping(3002)

out 1, 2, 3, 3

At 3002 the window is [2, 3002], so ping 1 no longer counts.

  • 1 ≤ t ≤ 10⁹
  • t strictly increases
  • At most 10⁴ calls

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

Design: implement every operation. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #362
      Design Hit Counter
      Mediumin QueuesLeetCode Premium
    2. #239