PROBLEM 67 OF 75

Meeting Rooms II

Find the minimum number of rooms needed for all meetings.

PATTERNIntervals & sweep lineAfter sorting, only the active frontier can conflict.
SPOT THE SIGNAL

Why does this pattern fit?

FRAME · 1 OF 4

Restate the exact job

Find the minimum number of rooms needed for all meetings.

WHY THIS FITS

A room frees when the earliest current end is no later than the next start.

COMPLEXITY

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

COMMON FAILURE

Comparing only with the previous meeting misses multiple concurrent meetings.

THE REASONING, IN ONE PLACE

How to solve Meeting Rooms II

The goal is to solve this problem from the pattern, not to memorize a finished answer. Use this as a check after your own attempt.

What the question asks

Find the minimum number of rooms needed for all meetings.

Why Intervals & sweep line fits

A room frees when the earliest current end is no later than the next start.

State to maintain

Meetings sorted by start and a min-heap of active end times.

Transition

Pop freed rooms, push the current end, and track maximum heap size.

Time and space

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

Counterexample to the tempting mistake

Comparing only with the previous meeting misses multiple concurrent meetings.

Prove it again tomorrow

Close this page. Rebuild the state and transition from memory, write a test that exposes the mistake above, then solve a fresh input without looking back. A same-day reread is practice, not proof of retention.

Open blank recall ↗