Code RoomHit rate sliding window
MediumPrep Room Coding #1426

Hit rate sliding window

CodingDistributed systemsAlgorithms & data structuresMid–Senior~25 min

Process a chronologically ordered list of events. Each event is `['hit', ts]` recording a hit at timestamp `ts` (seconds), or `['get', ts]` asking how many hits occurred in the most recent 300-second window, i.e. with timestamp strictly greater than `ts - 300` (the window is `(ts-300, ts]`). Timestamps are non-decreasing. Return the list of answers, one per `get` event, in order.

Implement
hit_counter(events: list[list]) → list[int]
Examples
in[[["hit",1],["hit",2],["hit",3],["get",4]]]out[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
InputExpectedGot
[[["hit",1],["hit",2],["hit",3],["get",4]]][3]not run yetsample