Compute max events in any 60-second window
Company: Marshall Wace
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This question evaluates understanding of timestamp and array processing, sliding-window or two-pointer techniques, and the ability to analyze time and space complexity when counting events within fixed-size intervals.
Constraints
- 0 <= len(timestamps) <= 10^6
- timestamps is sorted in non-decreasing order
- timestamps may contain duplicate values (multiple events in the same second)
- Timestamps are integers and may be negative, zero, or positive
- A 60-second window is inclusive on both ends: events t seconds apart count together when t <= 60
Examples
Input: ([1, 2, 3, 61, 62],)
Expected Output: 4
Explanation: The window from 2 to 62 spans 60 seconds (62-2=60) and contains 2,3,61,62 = 4 events. Including timestamp 1 would span 62-1=61 > 60, so it is excluded.
Input: ([],)
Expected Output: 0
Explanation: No events at all, so the maximum count in any window is 0.
Hints
- The list is already sorted, so you never need to re-scan backwards — a forward two-pointer (sliding window) suffices.
- Expand the window by moving the right pointer one event at a time; whenever timestamps[right] - timestamps[left] exceeds 60, move the left pointer forward to shrink it.
- The window is inclusive, so the condition to shrink is strictly '> 60', not '>= 60'. Track the largest (right - left + 1) you ever observe.