Meeting Rooms II

MediumIntervalssweep / heap

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

You are given a list of meetings, where each meeting is described by a pair [start, end] representing the time the meeting begins and the time it ends. Your task is to determine the minimum number of meeting rooms required so that every meeting can take place without two meetings ever sharing a room at the same time. The input intervals is a 2D array where intervals[i] = [start_i, end_i] with start_i < end_i. Treat the end time as **exclusive**: a meeting that ends exactly when another begins does **not** overlap with it, so the two can reuse the same room. For example, a meeting [5, 10] and a meeting [10, 15] can share one room. Return the smallest number of rooms that can host all of the meetings.

Examples

Input: intervals = [[0,30],[5,10],[15,20]]
Output: 2
The meeting [0,30] overlaps with both [5,10] and [15,20], but those two do not overlap each other. So one room holds [0,30] while a second room hosts [5,10] then [15,20] in sequence. Two rooms suffice.
Input: intervals = [[7,10],[2,4]]
Output: 1
[2,4] finishes before [7,10] starts, so a single room can host both back to back.
Input: intervals = [[1,5],[5,10],[10,15]]
Output: 1
Each meeting ends exactly when the next one begins. Because end times are exclusive, none of them overlap, so one room is enough.

Constraints

  • `0 <= intervals.length <= 10^4`
  • `intervals[i].length == 2`
  • `0 <= start_i < end_i <= 10^6`
  • An empty list of meetings requires `0` rooms.

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.