Problem · Intervals

Minimum Meeting Rooms with Assignments

Learn this problem
MediumUber logoUberFULLTIMEONSITE INTERVIEW
See Uber hiring insights

Problem 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 t may host another meeting starting at t.
  • 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

  • meetings is non-empty.
  • Each meeting has exactly two signed integer times with start < end.

More Uber problems

drafts saved locally
public int[] assignMeetingRooms(int[][] meetings) {
    // TODO: minimize rooms and return deterministic assignments.
}
meetings[[0,30],[5,10],[15,20]]
expected[2,0,1,1]
checking account