mediumSort by start and sweepSortingTwo pointers target 25 min
Meeting rooms needed
Each item of meetings is a pair [start, end] with start < end: a meeting that needs a room from start until end. A room holds one meeting at a time, and it is free again the moment its meeting ends, so a meeting that ends at 3 and one that starts at 3 can use the same room. The meetings come in any order.
Return the smallest number of rooms that lets every meeting happen.
Example 1
Input
meetings = [[1, 4], [2, 5], [6, 8]]Output2[1, 4] and [2, 5] both run from 2 to 4. [6, 8] reuses a room.
Example 2
Input
meetings = [[1, 3], [3, 5], [5, 7]]Output1Each meeting starts as the previous one ends, so one room is enough.
Example 3
Input
meetings = [[0, 10], [1, 4], [2, 3], [5, 9]]Output3At time 2, [0, 10], [1, 4] and [2, 3] are all running.
Constraints
0 ≤ len(meetings) ≤ 105
0 ≤ start < end ≤ 106
Plan it first
Write a line for each before you code, then say them out loud. Compare with the Approach tab afterwards.
Run examples checks the examples. Submit runs every test, including edge cases and, when the problem has one, a speed check on a large input.