Problem · Array
Minimum Meeting Rooms
Learn this problemProblem statement
You are given a list of n meetings. Each meetingTimings[i] = [start, end] contains the start time and end time of one meeting.
Assign every meeting to a room under these rules:
- No two overlapping meetings may use the same room.
- A meeting that ends at time
tand another meeting that starts at timetdo not overlap and may use the same room. - A zero-duration meeting
[t, t]still receives a room assignment, but it does not overlap any meeting. Zero-duration meetings may reuse the same room.
Return the minimum number of rooms needed to schedule all meetings.
Function
minMeetingRooms(meetingTimings: int[][]) → intExamples
Example 1
meetingTimings = [[1,4],[1,5],[5,6],[6,10],[7,9]]return = 2The meetings [1,4] and [1,5] overlap, so at least two rooms are required. Two rooms are sufficient because a meeting ending at time t can share a room with one starting at time t. The meetings [6,10] and [7,9] also occupy the two rooms concurrently.
Example 2
meetingTimings = [[1,2],[2,3],[3,4]]return = 1Each meeting starts exactly when the preceding meeting ends, so one room can host all three meetings.
Constraints
1 <= meetingTimings.length <= 2 * 10^5meetingTimings[i].length == 21 <= meetingTimings[i][0] <= meetingTimings[i][1] <= 2 * 10^6