Problem · Array

Meeting Rooms II

Learn this problem
MediumWalmart logoWalmartFULLTIMEPHONE SCREEN

Problem statement

You are given an array of meeting intervals intervals, where each interval is [start, end). Return the minimum number of rooms required to schedule every meeting without overlap.

Intervals are half-open: when one meeting ends at the exact time another begins, they do not overlap and may use the same room. Return 0 when intervals is empty.

Function

minMeetingRooms(intervals: int[][]) → int

Examples

Example 1

intervals = [[0,30],[5,10],[15,20]]return = 2

The meeting from 0 to 30 overlaps both shorter meetings, while those two shorter meetings can share a second room.

Example 2

intervals = [[0,8],[8,10],[10,15]]return = 1

Each meeting starts exactly when the previous meeting ends, so one room can be reused.

Example 3

intervals = []return = 0

No meetings require no rooms.

Constraints

  • 0 <= intervals.length <= 100000
  • intervals[i].length == 2
  • -2147483648 <= intervals[i][0] < intervals[i][1] <= 2147483647
  • Meetings use half-open intervals, so an end time equal to another start time is not an overlap.

More Walmart problems

drafts saved locally
public int minMeetingRooms(int[][] intervals) {
  // write your code here
}
intervals[[0,30],[5,10],[15,20]]
expected2
checking account