Code RoomRequest rate counter
MediumPrep Room Coding #1152

Request rate counter

CodingAlgorithms & data structuresMid–Senior~20 min

Implement a request rate counter. Calls arrive with strictly increasing timestamps (milliseconds). For each call, after recording its timestamp, return the number of recorded calls whose timestamp falls within the inclusive window [t - window_ms, t]. Given the window size and a list of timestamps, return a list with the count after each call. Timestamps are non-decreasing; treat equal timestamps as valid separate calls.

Implement
rate_counter(window_ms: int, timestamps: list[int]) → list[int]
Examples
in[3000,[1,100,3001,3002]]out[1,2,3,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 20 min
InputExpectedGot
[3000,[1,100,3001,3002]][1,2,3,3]not run yetsample