Problem · Array

Meeting Rooms II

MediumRobloxPHONE SCREEN
See Roblox hiring insights

Given an array of meeting time intervals consisting of start and end times [[start_1, end_1], [start_2, end_2], ...] where start_i < end_i, find the minimum number of meeting rooms required to schedule all meetings without any conflicts.

Intervals are half-open: a meeting that ends exactly when another begins does not conflict. For example, (0, 8) and (8, 10) are not considered a conflict at time 8 and can share a room.

A common approach sorts the start and end times (or uses a min-heap of meeting end times): sweep the events in time order, and track the maximum number of meetings that are simultaneously in progress, which is the number of rooms required.

Examples
01 · Example 1
intervals = [[0, 40], [5, 10], [15, 20]]
return = 2
Room 1 holds (0, 40). Room 2 holds (5, 10) and then (15, 20), which do not overlap each other. The meeting (0, 40) overlaps both of the others, so a second room is required, giving 2 rooms total.
02 · Example 2
intervals = [[4, 9]]
return = 1
There is a single meeting, so exactly one room is needed.
03 · Example 3
intervals = [[0, 8], [8, 10]]
return = 1
The first meeting ends at 8 exactly when the second begins. Half-open intervals do not conflict at the shared endpoint, so both fit in a single room.
Constraints
  • 0 <= intervals.length <= 500
  • intervals[i].length == 2
  • 0 <= intervals[i][0] < intervals[i][1] <= 1000000
  • An interval that ends exactly when another starts does not count as a conflict.
More Roblox problems
drafts saved locally
public int minMeetingRooms(int[][] intervals) {
  // write your code here
}
intervals[[0, 40], [5, 10], [15, 20]]
expected2
sign in to submit