DSA AnimatorDSA animations
Meeting Rooms II LC #253 Medium Intervals · Min-Heap
Problem

Given an array of meeting time intervals [[start, end], ...], return the minimum number of conference rooms required.

Example
Input: [[0,30],[5,10],[15,20]]
Output: 2
Explanation: [0,30] uses room 1. [5,10] needs new room (5<30). [15,20] can reuse room 1 (15>10).
Try Examples
Approach
Sort by Start + Min-Heap of End Times
If meeting.start ≥ heap.peek() → room free, poll and reuse. Else → allocate new room. Heap size = rooms in use.
Meeting Schedule
Load an example to begin.
Rooms in use —
Variables
Meeting
—
heap.peek()
—
Reuse?
—
Action
—
Step Logic
Press ▶ Play or Next Step to begin.
✓
Ready
0 / 0
Select an example and press Play.
Algorithm
1
Sort by start time
2
Min-heap stores end times of ongoing meetings
3
If start ≥ peek() → poll (reuse), else new room. Offer(end)
Time
O(n log n)
Space
O(n)
Why Heap

The min-heap tracks when rooms free up. If the earliest-ending meeting ends before the current meeting starts, we reuse that room. Otherwise we need a new room. Heap size = concurrent meetings = rooms needed.

How to solve Meeting Rooms II

LeetCode 253 · Medium · Intervals · Pattern: Min Heap of End Times

Why the obvious approach is slow

Checking every time point and counting overlaps is slow. We only need to know which room frees up first.

The key idea

Sort the meetings by start time. Keep a min heap of end times, one per room in use. If the earliest end is not after the new start, reuse that room, otherwise open a new one.

Remember

The heap top is the room that frees up first. The heap size is the number of rooms in use.

Run the animation above on your own input, or watch the 1:10 video explanation of Meeting Rooms II with a dry run and Java code.

More Intervals problems