Skip to content
mlmentorship

Meeting Rooms

Check whether one person can attend every meeting.

Published · 3 min read ·Core ·Mixed

30-second answer map

Visual first · depth when needed

Sorting by start time makes the first overlap appear between adjacent meetings, so Python all can stop at the first failed boundary check.

Preparing the visual…

ML breadth · active recall

Practice before you read

8 minutes. Explain the mechanism, why it works, when it fails, and one alternative.

How practice works

ML breadth · closed-book attempt

Meeting Rooms

Explain the mechanism, why it works, when it fails, and one alternative.

08:00recommended time

Closing or reloading clears the scratchpad. Only score, weak rubric dimensions, attempt count, and retry date can be stored locally.

Check whether one person can attend every meeting.

Start with the concrete trace below. It shows the state the algorithm must carry as it runs.

Problem trace

Meeting Rooms: Sorting by start time makes the first overlap appear between adjacent meetings, so Python all can stop at the first failed boundary check.

Input and goalCheck whether one person can attend every meeting.
Start with unsorted meetingsUse intervals [[7,10],[2,4],[12,14],[9,11]]. Their input order does not reveal the chronological neighbor checks.
[7,10]
[2,4]
[12,14]
[9,11]
input[[7,10],[2,4],[12,14],[9,11]]

Recognize it
Use it when one resource must handle every interval and any temporal overlap makes the schedule invalid.
Keep true
Before checking index i, all adjacent boundaries before i are non-overlapping. In start-sorted order, any overlap must include an adjacent pair, so the first failed comparison proves impossibility.
Reuse it
Sort to make a global conflict local, then compare neighboring boundaries and stop at the first violation. This transfers to overlap validation, booking conflicts, and disjoint-range checks.
Read it this way: Use intervals [[7,10],[2,4],[12,14],[9,11]]. Their input order does not reveal the chronological neighbor checks. Step through the frames to watch the state change. The last frame shows the answer or the stopping condition.

Pattern: Sort intervals by start.

Simple idea: After sorting, only neighboring meetings can reveal the first overlap. Each meeting must start at or after the previous meeting ends.

def can_attend_meetings(intervals: list[list[int]]) -> bool:
   intervals.sort()
   return all(
      intervals[index - 1][1] <= intervals[index][0]
      for index in range(1, len(intervals))
   )

Cost: time and extra space, not counting sorting.