Design Hit Counter Problem
Design Hit Counter Problem — ExecCode Medium DSA Practice
Solve the Design Hit Counter problem on ExecCode. Free online medium DSA practice in Design. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Design a hit counter which counts the number of hits received in the past 5 minutes (i.e., the past 300 seconds). Each function accepts a timestamp parameter (in seconds granularity).
Examples
Input ops = ["hit", "hit", "hit", "hit", "hit", "getHits"], vals = [1, 2, 3, 300, 301, 301]; Output [4]. Input ops = ["hit", "hit", "hit", "getHits", "hit", "getHits"], vals = [1, 2, 3, 4, 300, 300]; Output [3, 4]. Input ops = ["hit", "getHits", "hit", "getHits"], vals = [100, 100, 500, 500]; Output [1, 1]
Constraints
1 ≤ timestamp ≤ 2×10⁹ Timestamps are non-decreasing across calls. At most 300 hits may fall in any 300-second window in interviews.
Practice Design Hit Counter free on ExecCode. Browse DSA problems, topic map, and placement guides.