Problem · Intervals
Minimum Meeting Rooms with Assignments
Learn this problemProblem statement
Given an unsorted array meetings, where meetings[i] = [start, end], assign every meeting to a room while using the minimum possible number of rooms.
- Intervals are half-open: a room used by a meeting ending at time
tmay host another meeting starting att. - Process meetings by increasing start time, then increasing end time, then original index.
- Reuse the smallest available room ID; otherwise allocate the next nonnegative room ID.
Return an array whose first value is the minimum room count and whose remaining values are the room IDs for meetings in their original input order.
Function
assignMeetingRooms(meetings: int[][]) → int[]Examples
Example 1
meetings = [[0,30],[5,10],[15,20]]return = [2,0,1,1]Meetings 1 and 2 reuse room 1, while the long first meeting occupies room 0.
Example 2
meetings = [[7,10],[2,4]]return = [1,0,0]The meetings do not overlap, so one room serves both despite the unsorted input.
Constraints
meetingsis non-empty.- Each meeting has exactly two signed integer times with
start < end.