17 Aug 2025CEasy

Number of Recent Calls

implement RecentCounter using circular queue to count requests within last 3000ms.

use circular queue to maintain sliding window of last 3000ms. on each ping, add timestamp and remove timestamps older than 3000ms. return queue size.

circular queue allows efficient enqueue and dequeue operations. maintain front and rear pointers, handle wraparound for circular behavior.

implementation

  • circular queue with fixed capacity
  • enqueue new timestamps
  • dequeue timestamps outside 3000ms window
  • return current queue size

complexity

O(1) amortized time per ping. O(1) space for queue (bounded by 3000ms window).

Solution files

CC/number-of-recent-calls/solution.c

Solution file content could not be loaded.