Meeting Rooms II
Find the minimum number of rooms needed for all meetings.
Why does this pattern fit?
Restate the exact job
Find the minimum number of rooms needed for all meetings.
A room frees when the earliest current end is no later than the next start.
O(n log n) time · O(n) space
Comparing only with the previous meeting misses multiple concurrent meetings.
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.