📖 4 min read
Last updated on

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 →

Interval timeline showing meetings [0,30], [5,10], [15,20] on a shared time axis — [5,10] and [15,20] both fall inside [0,30], showing the overlap that prevents attending all meetings.

What Interviewers Are Actually Testing

SkillWhat Interviewers Observe
Sort-then-scan patternDo you know that sorting by start time enables linear overlap detection?
Overlap definitionDo you correctly define when two intervals overlap?
Edge casesEmpty array, single interval, touching intervals (end == next start)?
Connection to harder problemsCan you explain how this leads to Meeting Rooms II?

Step 1: Clarifying Questions

  1. 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.
  2. Can the array be empty? Return true — no meetings means no conflicts.
  3. 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

  1. Sort intervals by start time.
  2. Iterate from index 1 to n-1.
  3. If intervals[i][0] < intervals[i-1][1]: return False (overlap found).
  4. 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, returns True.
  • Single meeting: same — range(1, 1) is empty, returns True.
  • Touching intervals [1,3],[3,5]: 3 < 3 is False → no overlap. Adjust to <= if touching counts as overlap.

Time & Space Complexity

AspectComplexity
TimeO(n log n) — dominated by sort
SpaceO(1) extra (in-place sort)

Common Interview Mistakes

  1. Using <= vs < without clarifying touching intervals. [1,3] and [3,5] — is this an overlap? Always clarify and be consistent.

  2. Not sorting first. Without sorting, you’d need to check all pairs — O(n²).

  3. Comparing wrong fields. Compare intervals[i][0] (start) with intervals[i-1][1] (end), not start with start.

  4. 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.



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:

Practice Like It's the Real Interview

Get instant feedback on your approach, communication, and code — powered by AI.

Start a Mock Interview →