Requirements
- Input: a list of intervals, where each interval is
[start, end]. - Output: the maximum number of intervals active at any single time.
- Intervals are closed: an interval ending at time
endis still active at that exact time. - In the meeting-room version, the input is
List<List<Integer>> meetingTimings; the return value is the minimum number of rooms needed.
Examples
Input: [[1, 3], [2, 4], [3, 6]]
Output: 3
At time 3, all three processes are active.
Input: [[2, 6], [1, 2], [3, 5]]
Output: 2
Notes
- The sweep-line solution sorts starts and ends. Because intervals are inclusive, a start at time
tmust be processed before an end at timetwhen counting concurrency. - A min-heap of end times also works for the meeting-room framing; pop only ends that are strictly before the current inclusive start.
- Difference-array / prefix-sum solutions are viable only when the time domain is small or coordinate-compressed. With times up to large values, sorted events or a heap are safer.
- This is the same algorithmic family as Meeting Rooms II; the IBM variant mainly changes the input container, story, and endpoint convention.
Preparation
- Implement both versions: sorted event pairs with tie-breaking, and min-heap over end times. Add a test where one interval starts exactly when another ends.
- Drill the complexity explanation: sorting dominates at
O(n log n), heap space isO(n), and coordinate compression changes the prefix-sum version from time-domain-sized memory toO(n)events.

