Problem · Intervals
Streaming Interval Peak Concurrency
Learn this problemProblem statement
Meeting intervals arrive one at a time in the given order. After every insertion, return the highest concurrency observed anywhere in the timeline so far.
- Intervals are half-open:
[start, end). - An interval ending at time
tdoes not overlap one starting att. - The intervals are not sorted in advance.
Return one integer per arrival.
Function
peakConcurrencyAfterEachInsert(intervals: int[][]) → int[]Examples
Example 1
intervals = [[1,5],[2,4],[5,7],[3,6]]return = [1,2,2,3]The fourth insertion makes three intervals overlap during [3,4). The endpoint at 5 is handled as an end before a start.
Example 2
intervals = [[10,20],[0,10],[20,30]]return = [1,1,1]The three intervals only touch at endpoints, so the peak remains one.
Constraints
intervalsis non-empty.- Every row is
[start, end]withstart < end. - Coordinates are signed integers.