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).