class HitCounter: def __init__(self): self.counters = dict() def hit(self, timestamp: int) -> None: self.counters[timestamp] = self.counters.get(timestamp, 0) + 1 def getHits(self, timestamp: int) -> int: return sum([v for k,v in self.counters.items() if k <= timestamp and timestamp - k < 300])