Hit counter
Design a hit counter that counts hits in the past 300 seconds (a 5-minute window). Operations come in non-decreasing timestamp order: ['hit', t] records a hit at second t; ['get', t] returns the number of hits in the window (t-299, t] inclusive of t, i.e. timestamps strictly greater than t-300. Use O(300) space via circular buckets. Return the list of results for each 'get'.
Implement
hit_counter(ops: list[list]) → list[int]Examples
in
[[["hit",1],["hit",2],["hit",3],["get",4],["hit",300],["get",300],["get",301]]]out[3,4,3]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 25 min
solution.py
InputExpectedGot
[[["hit",1],["hit",2],["hit",3],["get",4],["hit",300],["get",300],["get",301]]][3,4,3]not run yetsample