Meeting Rooms II
MediumIntervals · Airbnb · Microsoft
You are given an array of meeting time intervals intervals, where intervals[i] = [start, end]. The meetings are not in any particular order.
Return the minimum number of conference rooms needed so that every meeting can be held, where a room can host only one meeting at a time.
A room becomes free at the moment its meeting ends: a meeting ending at time t and another starting at time t can use the same room.
Example 1
- Input:
- intervals = [[0, 6], [2, 4], [3, 9], [4, 7]]
- Output:
- 3
- Explanation
- At time 3 the meetings
[0, 6],[2, 4]and[3, 9]are all running, so 3 rooms are needed. At time 4 the room from[2, 4]frees up just as[4, 7]starts, so a 4th room is never needed.
Example 2
- Input:
- intervals = [[7, 10], [2, 4]]
- Output:
- 1
- Explanation
- The meetings never overlap, so one room hosts both.
Example 3
- Input:
- intervals = [[1, 10], [10, 20], [20, 30]]
- Output:
- 1
- Explanation
- Each meeting starts exactly when the previous one ends, so the same room can be reused every time.
Constraints
1 <= intervals.length <= 10^4intervals[i].length == 20 <= start < end <= 10^6