Design Hit Counter

medium
Design a hit counter which counts the number of hits received in the past 5 minutes (i.e., the past 300 seconds).

Your system should accept a timestamp parameter (in seconds granularity), and you may assume that calls are being made to the system in chronological order (i.e., timestamp is monotonically increasing). Several hits may arrive roughly at the same time.

Implement the HitCounter class:

HitCounter() Initializes the object of the hit counter system.
void hit(int timestamp) Records a hit that happened at timestamp (in seconds). Several hits may happen at the same timestamp.
int getHits(int timestamp) Returns the number of hits in the past 5 minutes from timestamp (i.e., the past 300 seconds).

Input Format

Input is managed for u

Output Format

.Input is managed for u

Constraints

1. 1 <= timestamp <= 2 * 10^9
2. All the calls are being made to the system in chronological order (i.e., timestamp is monotonically increasing).
3. At most 300 calls will be made to hit and getHits.

Notice

.

Example

Input
hit 1
hit 2
hit 3
getHits 4
hit 300
getHits 300
getHits 301
exit
Output
3
4
3
Previous
Maximum Sum Of Two Non-overlapping Subarrays
Next
Island Perimeter

Related Questions