Design Hit Counter
Difficulty: Medium
Category: DSA
Topics: Array, Binary Search, Design, Queue, Data Stream
Asked at: Amazon, Microsoft, Apple, Bloomberg, Google, Yandex
You are given a class `HitCounter` that records hits at given timestamps (in seconds). Implement the following methods:
- `hit(timestamp)`: Records a hit that happened at the given `timestamp` (an integer representing the current time in seconds).
- `getHits(timestamp)`: Returns the number of hits recorded in the past 5 minutes (i.e., in the time interval `[timestamp - 299, timestamp]`, inclusive).
Both methods will be called with timestamps in chronological order (i.e., the `timestamp` parameter is always greater than or equal to the previous calls).
Return the number of hits in the past 5 minutes for each call to `getHits`.