bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 362. Design Hit Counter

362. Design Hit Counter

Leetcode Solutions

Using Queue to Track Hits

  1. Initialize an empty queue in the constructor of the HitCounter class.
  2. When hit is called, add the timestamp to the queue.
  3. When getHits is called, dequeue timestamps from the front of the queue until all timestamps are within the last 5 minutes of the current timestamp.
  4. Return the size of the queue as the number of hits in the last 5 minutes.
UML Thumbnail

Using Fixed-Size Array to Track Hits

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...