Maximum Events in a 60-Second Window
Problem statement
You are given a list of event timestamps, sorted in non-decreasing order and measured in seconds. Find the maximum number of events in any 60-second window.
For this exercise, a window starting at time t includes events in [t, t + 60): the start is included and the end is excluded. Events exactly 60 seconds apart cannot share one window. Repeated timestamps represent separate events.
Return 0 when the list is empty.
Function
solution(timestamps: int[]) → intExamples
Example 1
timestamps = [1,30,59,60,61]return = 4The window [1,61) contains events at 1, 30, 59 and 60. No window contains all five.
Example 2
timestamps = [0,60]return = 1The two events are exactly 60 seconds apart, so the half-open convention prevents them from sharing a window.
Example 3
timestamps = [5,5,5,64,65]return = 4The window [5,65) contains the three events at 5 and the event at 64, but excludes the event at 65.
Example 4
timestamps = []return = 0There are no events to count.
Constraints
0 <= timestamps.length <= 200000.- Every timestamp is an integer between
0and10^9, inclusive. timestampsis sorted in non-decreasing order.