Design hit counter and log storage system
Create a tracker that records the number of hits received within the last five minutes.
Each method receives a timestamp (in seconds) as input, and you can assume the timestamps are provided in increasing order (i.e., the timestamp values never decrease). The earliest timestamp will always start at 1.
Multiple hits may occur at the same timestamp.
HitTracker tracker = new HitTracker(); // record a hit at second 1 tracker.recordHit(1); // record a hit at second 2 tracker.recordHit(2); // record a hit at second 4 tracker.recordHit(4); // get the number of hits at second 5, should return 3 tracker.getRecentHits(5); // record a hit at second 301 tracker.recordHit(301); // get the number of hits at second 301, should return 4 tracker.getRecentHits(301); // get the number of hits at second 302, should return 3 tracker.getRecentHits(302);
recordHit
and getRecentHits
are made in non-decreasing order of timestamp