Meeting Rooms II
Problem statement
You are given a list of meetings, intervals, where intervals[i] = [starti, endi]. A meeting uses a room from starti up to, but not including, endi.
Return the minimum number of rooms needed so that every meeting has a room for its whole time. Two meetings cannot use the same room at the same moment.
A room whose meeting ends at time t can be used by another meeting that starts at time t.
Function
minMeetingRooms(intervals: int[][]) → intExamples
Example 1
intervals = [[9,12],[13,15],[11,14]]return = 2The meetings [9, 12] and [11, 14] run at the same time from 11 to 12, so two rooms are needed. The meeting [13, 15] can use the first room, which is free from time 12. Two rooms are enough.
Example 2
intervals = [[1,4],[4,7],[7,10]]return = 1Each meeting starts exactly when the one before it ends, so one room can host all three.
Example 3
intervals = [[2,10],[3,5],[4,6],[5,8]]return = 3At time 4 the meetings [2, 10], [3, 5], and [4, 6] are all running, so at least three rooms are needed. At time 5 the meeting [3, 5] has ended and [5, 8] takes its room. At no moment are four meetings running, so the answer is 3.
Constraints
1 <= intervals.length <= 5000intervals[i].length == 20 <= starti < endi <= 10^6