Skip to content
AI360Xpert
Beta
Difficulty: EasyIntervals

Meeting Rooms

Problem in Plain English

You are given a list of meeting time intervals and must decide whether a single person can attend all of them. Return true only when no two meetings overlap.

Problem Statement

Given an array intervals where intervals[i] = [start_i, end_i] is a meeting, determine whether one person can attend every meeting.

Two meetings overlap when each starts before the other ends; meetings that merely touch, like [1,2] and [2,3], do not conflict. Return true if all meetings can be attended and false otherwise.

Constraints

  • 0 <= intervals.length <= 10^4
  • intervals[i].length == 2
  • 0 <= start_i < end_i <= 10^6

Examples

Example 1

Input
intervals = [[0,30],[5,10],[15,20]]
Output
false

Meetings [0,30] and [5,10] overlap since 5 < 30, so one person cannot attend both.

Example 2

Input
intervals = [[7,10],[2,4]]
Output
true

No two meetings overlap, so one person can attend all of them.

Example 3

Input
intervals = []
Output
true

There are no meetings and therefore no conflicting pair. The empty schedule is attendable.

Example 4

Input
intervals = [[2,3],[0,1],[1,2]]
Output
true

In chronological order the meetings are [0,1], [1,2], [2,3]. Each starts exactly when the previous one ends, so a person can attend all three.

Example 5

Input
intervals = [[0,10],[10,12],[2,3]]
Output
false

The first two meetings touch without conflict, but the later-listed [2,3] lies inside [0,10]. Checking only original-order neighbors would miss that conflicting pair.

Intuition

A person can attend all meetings only if no two occupy time simultaneously. Ending one meeting exactly when the next starts is allowed. Example 1 fails because the long meeting [0,30] contains [5,10]. Testing all pairs detects that directly; ordering meetings by start lets us certify the schedule by checking adjacent meetings only.

Approaches

Brute Force

Solution Details

Reveal Brute Force: intuition, complexity, and code

Hints

Hint 1
Two meetings [a,b] and [c,d] overlap exactly when a < d and c < b.
Hint 2
Checking every pair works but repeats work on large inputs.
Hint 3
Sort by start time first; then any conflict must appear between two neighbours.

Edge Cases

  • An empty list or a single meeting trivially returns true, since nothing can conflict.
  • Back-to-back meetings like [1,2] and [2,3] do not overlap and return true.
  • Two identical meetings such as [1,5] twice overlap and return false.
  • Nested meetings and equal starts both conflict; checking only endpoints in original order can miss them.

Common Mistakes and Interview Tips

  • Skipping the sort and only comparing neighbours in the original order, which misses conflicts between distant entries.
  • Using <= in the overlap test, so back-to-back meetings are wrongly flagged as conflicts.
  • Claiming every overlapping pair becomes adjacent after sorting is false. The proof is that if all adjacent pairs are disjoint, then every pair is disjoint.
  • Sorting the caller array changes its order; copy the outer container when preservation is required.
  • Interview tip: distinguish this strict meeting-time overlap from Merge Intervals, where closed intervals sharing an endpoint must merge.

Key Takeaway

When passing every adjacent check in start-time order proves every pair is disjoint, sorting turns an all-pairs conflict search into one neighbor scan.