Loading problem…
Design a time-based hit counter tracking system.
Implement
class HitCounter {
hit(timestamp) {}
getHits(timestamp) {}
}hit(timestamp): Record a request event that occurred at the specified timestamp.getHits(timestamp): Return the total hits recorded within the past 300 seconds.(timestamp - 300, timestamp]).const 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