Your question is Fixed-Window Packet Rate Limit. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Given a non-decreasing array of integer timestamps timestamps and an integer window_size, return an array where each element is the number of events that occurred within the inclusive time window [timestamps[i] - window_size + 1, timestamps[i]]. Implement an efficient algorithm that processes the timestamps in one pass.
def count_events_in_window(timestamps, window_size):