Problem Statement
Meeting Rooms
You are given a list of meetings. Each meeting is written as [start, end], which means it begins at the start time and finishes at the end time. The question is simple: can one person go to every single meeting without ever being in two places at once? That only works if no two meetings overlap. Two meetings overlap when one begins before the other has ended. The trick that makes this easy is to line the meetings up in time order, like reading a calendar from top to bottom. Once they are in order, you only have to compare each meeting with the one right before it.
Signals to notice
Brute force first
Check every pair for overlap. That direct path helps you understand the question, but it tends to treat every possibility as brand new instead of learning from earlier steps.
The key insight
Sort by start time. If any meeting starts before the previous one ends, there's a conflict. Instead of recomputing the world every time, you preserve just enough context to let the next decision become obvious.
Trace it on intervals=[[0,30],[5,10],[15,20]]
sort by start -> [[0,30],[5,10],[15,20]] (already ordered) i=1: cur=[5,10], prev=[0,30] -> 5 < 30 -> overlap found return false
What must stay true
After sorting by start time, overlapping meetings are adjacent. If meetings[i].start < meetings[i-1].end, they conflict. As long as that statement keeps holding, you can trust the steps built on top of it.
Shape of the loop
sort intervals by start
for i from 1 to n-1:
if intervals[i].start < intervals[i-1].end:
return false
return truePseudocode only — the full worked solution lives in the Solution tab.
Easy way to go wrong
Not considering equal boundaries — meetings [1,3] and [3,5] don't overlap (one ends as the other starts). Use < not ≤ for the overlap check. When the code becomes mechanical before the idea is clear, small edge cases start breaking the whole story.