Intervals
Medium
Meeting Rooms II
Find the minimum number of conference rooms required.
10 min read
Solve on LeetCodeProblem Understanding
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), find the minimum number of conference rooms required.
Example:
- Input:
[[0,30],[5,10],[15,20]] - Output:
2 - Explanation: Meeting 1 (
0-30) requires a room. Meeting 2 (5-10) overlaps, so it needs a new room. Meeting 3 (15-20) also overlaps with Meeting 1, but it starts after Meeting 2 ends, so it can reuse Meeting 2's room.
Algorithm Strategy
To minimize rooms, we want to "recycle" rooms as soon as they become free.
- Sort: Sort meetings by start time.
- Min-Heap (Priority Queue): Use a Min-Heap to store the end times of active meetings. The size of the heap represents the number of rooms currently in use.
- Process: For each meeting:
- Check the room that finishes earliest (top of Min-Heap).
- If
top <= current.start, that room is free! Poll the heap (removetop) to reuse it. - Push the
current.endto the heap (representing the room now occupied untilcurrent.end).
- Result: The size of the heap at the end (or max size reached) is the answer.
Alternatively, Chronological Ordering method (Sort Starts and Ends separately) also works.
Interactive Visualization
Step 1 / 1
Initializing...
1x
See the Logic in Motion
Stop memorizing code. Unlock the full interactive visualizer to master the logic step-by-step.ON THIS PAGE
- Problem Understanding
- Algorithm Strategy
- Interactive Visualization
- Dry Run
- Edge Cases & Common Mistakes
- Solution
Stop Guessing, Start Mastering.
Build the FAANG intuition. Master this pattern with optimized implementations, visual dry runs, and our curated collection of high-yield problems.
