Browse Curriculum
FAANGPrep Sprint
Medium

Meeting Rooms II

Find the minimum number of conference rooms required.

Problem 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.

  1. Sort: Sort meetings by start time.
  2. 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.
  3. 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 (remove top) to reuse it.
    • Push the current.end to the heap (representing the room now occupied until current.end).
  4. 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

Watch how we allocate spaces (rooms) based on availability.

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.