Intervals Merging and scheduling
512. Most Meetings in One Room
There is one meeting room and a list of meetings. Meeting i starts at time start[i] and ends at time
end[i]. The room holds one meeting at a time. Return the largest number of meetings that can be held in it.
A meeting has the room from its start to its end, both included. So a meeting can only start strictly after
the one before it ends. After a meeting that ends at 5, the next one can start at 6, but not at 5. With
start = [1,5] and end = [5,8], only one of the two meetings can be held. This is stricter than Meeting
Rooms and Non-overlapping Intervals, where a meeting may start at the moment another one ends.
A meeting may start and end at the same time. It still has the room at that moment.
Example 1
Input: start = [4, 1, 6, 3, 9, 10]
end = [5, 3, 8, 7, 12, 11]
4Explanation: The meetings from 1 to 3, 4 to 5, 6 to 8 and 10 to 11 can all be held, one after another. The meeting from 3 to 7 clashes with three of them, since it starts at 3, when the first one ends. The one from 9 to 12 clashes with the one from 10 to 11.
Example 2
Input: start = [1, 3, 5], end = [3, 5, 7]
2Explanation: The meeting from 3 to 5 starts when the first one ends and ends when the last one starts, so it clashes with both. The other two can be held. If a meeting could start when the one before it ends, all three would fit.
Example 3
Input: start = [0, 0, 2, 2], end = [0, 1, 2, 4]
2Explanation: The meetings from 0 to 0 and from 2 to 2 take no time, but each still has the room at its moment. The meeting from 0 to 1 cannot follow the one from 0 to 0, because it starts at 0, not after it.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
1 ≤ start.length ≤ 105end.length = start.length0 ≤ start[i] ≤ end[i] ≤ 109
Clarifying questions
What you would ask an interviewer before writing any code.