DSA Tracker

Medium

Meeting Rooms II

A medium Intervals interview guide. Task statement, worked examples, intuition, and step-by-step solutions.

Topic
Intervals
Sheets
2
Core for
6 roles

The problem

Given an array of meeting time intervals, find the minimum number of meeting rooms required.

Example 1

Input
intervals = [[0,30],[5,10],[15,20]]
Output
2
Why
The intervals [0,30] and [5,10] overlap, requiring two rooms. At time 15, [0,30] and [15,20] overlap, still two rooms.

Example 2

Input
intervals = [[7,10],[2,4]]
Output
1
Why
The intervals do not overlap, so one room suffices.

Constraints

  • 1 <= intervals.length <= 10^4
  • intervals[i].length == 2
  • 0 <= intervals[i][0] < intervals[i][1] <= 10^6

How to think about it

Updated 2026-09-09

The number of rooms you must provide is determined solely by the peak concurrent load. Which specific meeting takes place in which room is irrelevant; what matters is how many meetings have started and not yet finished at any given point along the timeline.

Approaches, worst first

  1. Sort and min-heap of end times

    time O(n log n) · space O(n)

    Sort meetings by start time and maintain a min-heap of active end times. For each meeting, if the earliest ending meeting finishes at or before the current start, recycle that room by popping it; then push the new end time. The heap's peak size is the answer.

  2. Two sorted pointersWrite this one

    time O(n log n) · space O(n)

    Split starts and ends into separate arrays and sort both ascending. Walk through starts: if the current start is strictly before the current end pointer, allocate a new room; otherwise, advance the end pointer because an existing room has emptied. Avoids heap overhead.

Where people lose marks · 3
  • Advancing an end pointer or popping the heap when `start == end`. A meeting starting at the exact instant another finishes can reuse that exact room, so do not count it as concurrent.
  • Sorting both arrays in-place together instead of decoupling starts and ends into independent sequences, which corrupts the start-end pairings in paired approaches.
  • Failing to account for single-meeting inputs: the answer must be 1, never 0.

The theory behind it

Intervals — the ground this problem stands on. All Intervals problems

What Intervals is

An interval is a continuous range of numbers defined by two values: a start point and an end point. Think of a calendar event booked from two to four o'clock, or a cut segment on a ruler. Because each interval covers every number between its boundaries, two intervals can sit apart with empty room between them, touch at an edge, or overlap across a shared span of numbers.

When to reach for it

Reach for intervals when the input consists of start and end pairs representing time slots, schedules, ranges, or geometric segments. Phrasings asking to merge overlapping blocks, insert a new meeting into a busy calendar, find the minimum number of conference rooms needed, or count how many intervals must be removed to eliminate overlaps all point directly to interval patterns. Whenever problems involve resource contention over time, think intervals.

How the pattern works

The opening move is almost always sorting the intervals by their start times, or occasionally by their end times. Once ordered, compare the current interval with the previous one. If the new start time is less than or equal to the previous end time, the two intervals collide; merge them by stretching the previous end time to the maximum of both ends. If they do not collide, the previous interval is finished, so append it to the result and start tracking the new one. For room counts, split intervals into separate start and end events.

More Intervals problems

Track in your role's order

Pick your target role and all 370 problems resequence to what that interview actually asks.

Start free

Problem set and role mapping as of .