Intervals Merging and scheduling
510. Meeting Rooms II
You are given an array intervals, where intervals[i] = [start, end] is a meeting that begins at time start
and ends at time end. Each meeting needs a room for its whole length, and a room holds one meeting at a time.
Return the fewest rooms that can hold every meeting.
A meeting uses its room from start up to end. A meeting may begin at the moment another one ends and take
over its room, so [1,4] and [4,6] can share a room.
Example 1
Input: intervals = [[8, 14],
[1, 6],
[3, 9],
[10, 12],
[5, 7]]
3Explanation: At time 5, the meetings [1,6], [3,9] and [5,7] are all running, so they need three rooms. Three are
enough: [8,14] takes the room [1,6] left, and [10,12] takes the room [5,7] left.
Example 2
Input: intervals = [[4, 7], [1, 4], [7, 9]]
1Explanation: Each meeting begins the moment the one before it ends, so one room holds all three.
Example 3
Input: intervals = [[0, 1000000000], [6, 8], [6, 8]]
3Explanation: The two copies of [6,8] run at the same time, and both run inside the long meeting. Each of the three
needs its own room.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
1 ≤ intervals.length ≤ 105intervals[i].length = 20 ≤ start < end ≤ 109
Clarifying questions
What you would ask an interviewer before writing any code.