Design Hit Counter
Problem Description
Design a hit counter which counts the number of hits received in the past 5 minutes (the past 300 seconds).
Your system should support:
- `void hit(int timestamp)`: record a hit at given timestamp (in seconds granularity).
- `int getHits(int timestamp)`: return the number of hits in the past 300 seconds (inclusive of current timestamp).
Assume timestamps are non-decreasing when called.
Example Test Cases
Example 1
Input: [["HitCounter","hit","hit","hit","getHits","hit","getHits","getHits"],[[],[1],[2],[3],[4],[300],[300],[301]]]
Expected: [null,null,null,null,3,null,4,3]
Example 2
Input: [["HitCounter","hit","getHits"],[[],[1],[300]]]
Expected: [null,null,1]
Run your code to see the results