Meeting Rooms
Sort the meetings by start time. Then walk through them and check one thing: does this meeting start before the previous meeting ends? If yes, they overlap. If that never happens, there is no clash anywhere.
Meeting i is fine when it starts at or after the previous meeting ends: intervals[i][0] ≥ intervals[i−1][1]. Equal is fine, because a meeting is over at its end time.
Problem
You get a list of meetings. Meeting i runs from intervals[i][0] to intervals[i][1].
One person wants to go to every meeting. Return true if no two meetings share any time, and false otherwise.
A meeting is over at its end time. So a meeting that ends at 10 and one that starts at 10 do not clash: you walk out of one and into the other.
A list intervals of [start, end] pairs.
true if one person can attend every meeting, false if any two of them overlap.
[0,30] is still running when [5,10] starts at 5, so you can't be in both.
[2,4] ends at 4, long before [7,10] starts.
The first meeting is over at 10, exactly when the second one starts. Touching is not overlapping.
- • 0 ≤ intervals.length ≤ 10^4
- • intervals[i].length == 2
- • 0 ≤ start < end ≤ 10^6
First, think yourself
Before opening any solution, try to answer these on paper. Use hints only when stuck — each hint is counted.
- 1.
When exactly do two meetings clash? Write the test for two meetings first.
- 2.
Is a meeting ending at 10 in conflict with one starting at 10?
- 3.
If I had to check meetings in some order, which order would put clashing meetings next to each other?
- 4.
After sorting, do I need to compare a meeting with everything before it, or only with one of them?
- 5.
What should the answer be for zero meetings or one meeting?
Brute force approach
Optimized approach
Why does this algorithm work?
Dry run
All approaches compared
| Approach | Idea | Time | Space |
|---|---|---|---|
| Brute Force | Check all n(n−1)/2 pairs of meetings for overlap | O(N²) | O(1) |
| Optimal | Sort by start; each meeting only needs checking against the previous one | O(N log N) | O(1) |
Why does this belong to this pattern?
- “list of [start, end] meetings”Interval input → sort first, then walk once.
- “attend all”Yes/no question: does ANY overlap exist? We can stop at the first one.
- “one person”At most 1 meeting may be active at any time. Meeting Rooms II asks how many are active at once.
This is the anchor of the scheduling sub-pattern. The question is "is the number of meetings running at once ever more than 1?". With one person, sorting and a neighbour check answer it. Meeting Rooms II asks for the maximum number running at once, which needs a sweep or a heap. Merge Intervals uses the same sort but combines overlapping meetings instead of rejecting them.
Don't make this mistake
[5,10] and [10,15] do not overlap: the first meeting is over at 10, and the second starts at 10. With <= you would wrongly return false.
Without sorting, the meeting just before i in the list is not the one just before it in time. [[10,20],[0,5]] has no clash at all, but the unsorted check sees 0 < 20 and wrongly returns false. Always sort first.
The one-sided test only catches meeting 2 starting inside meeting 1. It misses meeting 1 starting inside meeting 2. The symmetric test catches every case, including one meeting inside the other.
This looks like Merge Intervals, so it is tempting to merge everything and compare the counts. That works, but it is extra work and extra space. Here you only need to find one clash: return false at the first one. Also, Merge Intervals treats touching intervals as overlapping ([1,4] and [4,5] merge), while here touching meetings are fine.
Want to implement this?
Write it yourself on LeetCode, then come back and compare your code with the solutions above.
Open coding workspaceHow this concept connects to System Design & C++ Systems
Top engineering interviews test whether you understand how algorithms like Intervals translate into production architectures and low-level memory mechanics.
Foundations: Object-Oriented Principles in C++23
Class invariants, pure virtual interfaces, and RAII smart pointers.
Food Delivery System (Zomato Architecture)
Real-world machine coding application of algorithms and design patterns.
Pointers vs References Deep Dive
Pointer arithmetic and memory layout under the hood.
Virtual Method Table (vtable) & Memory Layout
Polymorphism, vptr overhead, and multiple inheritance in memory.