FastPrepMaximum Events in a 60-Second Window

Maximum Events in a 60-Second Window

Marshall Wace logoMarshall Wace● EasyFULLTIMEOA

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[]) → int

Examples

Example 1

timestamps = [1,30,59,60,61]return = 4

The window [1,61) contains events at 1, 30, 59 and 60. No window contains all five.

Example 2

timestamps = [0,60]return = 1

The 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 = 4

The window [5,65) contains the three events at 5 and the event at 64, but excludes the event at 65.

Example 4

timestamps = []return = 0

There are no events to count.

Constraints

  • 0 <= timestamps.length <= 200000.
  • Every timestamp is an integer between 0 and 10^9, inclusive.
  • timestamps is sorted in non-decreasing order.

More Marshall Wace problems

See Marshall Wace hiring insights
Saved
public int solution(int[] timestamps) {
    // Write your solution here.
}
timestamps[1,30,59,60,61]
expected4
Checking account…