Loading problem…
Design a hit counter that counts the number of hits received in the past 5 minutes (300 seconds).
Implement a HitCounter class with the following methods:
hit(timestamp): Record a hit at the given timestamp (in seconds)getHits(timestamp): Return the number of hits in the past 5 minutes (300 seconds) from the given timestampconst counter = new HitCounter();
counter.hit(1); // hit at timestamp 1
counter.hit(2); // hit at timestamp 2
counter.hit(3); // hit at timestamp 3
counter.getHits(4); // get hits at timestamp 4, return 3
counter.hit(300); // hit at timestamp 300
counter.getHits(300); // get hits at timestamp 300, return 4
counter.getHits(301); // get hits at timestamp 301, return 3