Meeting Rooms — Coding Interview Walkthrough
Meeting Rooms is the gateway to an entire family of interval problems. The question itself is simple — can one person attend all meetings? — but it establishes the sort-by-start-time pattern that you’ll use in Merge Intervals, Meeting Rooms II, and Insert Interval. Getting this one right quickly signals that you understand the interval toolkit.
The Problem
Given an array of meeting time intervals intervals where intervals[i] = [start_i, end_i], determine if a person can attend all meetings (i.e., no two intervals overlap).
Example 1
Input: intervals = [[0,30],[5,10],[15,20]]
Output: false — [0,30] overlaps with both [5,10] and [15,20].
Example 2
Input: intervals = [[7,10],[2,4]]
Output: true — [2,4] ends before [7,10] starts.
Already comfortable with the solution? Practice it in a mock interview →
What Interviewers Are Actually Testing
| Skill | What Interviewers Observe |
|---|---|
| Sort-then-scan pattern | Do you know that sorting by start time enables linear overlap detection? |
| Overlap definition | Do you correctly define when two intervals overlap? |
| Edge cases | Empty array, single interval, touching intervals (end == next start)? |
| Connection to harder problems | Can you explain how this leads to Meeting Rooms II? |
Step 1: Clarifying Questions
- Do touching intervals count as overlapping?
[1,3]and[3,5]— does this person need to be in two places at time 3? Always clarify. - Can the array be empty? Return
true— no meetings means no conflicts. - Are intervals given in sorted order? Usually no — assume arbitrary order.
Step 2: The Naive Idea
Compare every pair of intervals: O(n²). For each pair, check if they overlap. Correct but inefficient.
Step 3: The Key Insight
Sort by start time. After sorting, the only interval that can overlap with interval i is interval i-1 — you only need to check adjacent pairs. If any meeting’s start time is before the previous meeting’s end time, there’s a conflict.
Overlap condition: intervals[i][0] < intervals[i-1][1]
Step 4: Optimal Strategy
- Sort
intervalsby start time. - Iterate from index 1 to n-1.
- If
intervals[i][0] < intervals[i-1][1]: returnFalse(overlap found). - Return
True.
Python Implementation
def canAttendMeetings(intervals: list[list[int]]) -> bool:
intervals.sort(key=lambda x: x[0]) # Sort by start time
for i in range(1, len(intervals)):
if intervals[i][0] < intervals[i - 1][1]:
return False # Current meeting starts before previous ends
return True
Edge cases handled:
- Empty array:
range(1, 0)is empty, returnsTrue. - Single meeting: same —
range(1, 1)is empty, returnsTrue. - Touching intervals
[1,3],[3,5]:3 < 3is False → no overlap. Adjust to<=if touching counts as overlap.
Time & Space Complexity
| Aspect | Complexity |
|---|---|
| Time | O(n log n) — dominated by sort |
| Space | O(1) extra (in-place sort) |
Common Interview Mistakes
-
Using
<=vs<without clarifying touching intervals.[1,3]and[3,5]— is this an overlap? Always clarify and be consistent. -
Not sorting first. Without sorting, you’d need to check all pairs — O(n²).
-
Comparing wrong fields. Compare
intervals[i][0](start) withintervals[i-1][1](end), not start with start. -
Not connecting to Meeting Rooms II. Interviewers often follow up with “how many rooms do you need?” — knowing this uses a min-heap on end times shows depth.
What a Strong Candidate Sounds Like
“Sort by start time. After sorting, I only need to check adjacent pairs — if any meeting starts before the previous one ends, there’s a conflict. That’s O(n log n) for sort plus O(n) for the scan. The key clarifying question is whether touching endpoints count as overlap.”
Example Interview Dialogue
Interviewer: What if I asked how many rooms you’d need?
Candidate: That’s Meeting Rooms II. I’d use a min-heap on end times. For each meeting, if its start is after the earliest ending meeting, I reuse that room. Otherwise I allocate a new one. The heap size at the end is the minimum rooms needed.
Interviewer: Why sort by start time specifically?
Candidate: Sorting by start time means that once I see interval i, all intervals before it start at or before intervals[i]. So the only potential overlap is with the immediately preceding interval — the one that ends latest among those already processed. That makes the check linear.
Related Problems to Practice
- Merge Intervals — Merge overlapping intervals. Same sort-first pattern.
- Meeting Rooms II — Minimum rooms needed. Min-heap on end times.
- Insert Interval — Insert a new interval into sorted non-overlapping list.
Practice This in a Mock Interview
Meeting Rooms is short enough that interviewers expect you to solve it quickly and then discuss extensions. Practice both the solution and the follow-up conversation about Meeting Rooms II.
Start a mock interview for Meeting Rooms on Intervu.
Further reading:
- How to Prepare for a Coding Interview in 2026, the complete roadmap
- Why LeetCode alone isn’t enough, and what to practice instead
- Practice any LeetCode problem as a live mock interview
- The Grind 75 Pathway, a structured study plan with AI practice links
- Browse all walkthroughs on GitHub