Meeting Rooms II
Signals to notice
Brute force first
For each meeting, count how many others overlap with it. Checks every pair. It is a fair place to begin because it matches the surface of the question, yet it does not capture the deeper structure that makes the problem simpler.
The key insight
Separate start and end times, sort both. Two pointers: if next event is a start, increment rooms; if end, decrement. Track the peak. Or use a min-heap of end times. Instead of recomputing the world every time, you preserve just enough context to let the next decision become obvious.
What must stay true
The minimum rooms needed equals the maximum number of simultaneously active meetings. Sorting events chronologically and tracking active count reveals this peak. As long as that statement keeps holding, you can trust the steps built on top of it.
Easy way to go wrong
Using a max-heap instead of min-heap — the min-heap tracks the earliest ending meeting. If a new meeting starts after it ends, reuse that room (pop and push). The fix is usually to return to the meaning of each move, not just the steps themselves.