Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

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 ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access