227/670

227. Meeting Rooms

Easy

You are given intervals, a list of meetings where intervals[i] = [start_i, end_i] means the i-th meeting runs from start_i up to (but not including) end_i. Return true if a single person could sit through the entire schedule — that is, if no two meetings ever overlap — and false otherwise.

Back-to-back meetings are fine: a meeting that begins exactly when another one ends does not count as a conflict.

Why [[0, 30], [5, 10], [15, 20]] fails
[0, 30][5, 10] overlaps [0, 30][15, 20] overlaps too051015202530

Example 1:

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

Output: false

Explanation: The meeting [5, 10] begins while [0, 30] is still in progress, so one person cannot attend both.

Example 2:

Input: intervals = [[7, 10], [2, 4]]

Output: true

Explanation: [2, 4] wraps up before [7, 10] begins, so the schedule never double-books.

Constraints:

  • 0 ≤ intervals.length ≤ 10⁴
  • 0 ≤ start_i < end_i ≤ 10⁶

Hints:

Two meetings [a, b] and [c, d] conflict exactly when a < d and c < b. Testing every pair against that condition already solves the problem.

Sort the meetings by start time. Then a conflict can only occur between neighbors: if every meeting starts at or after the previous one ends, the whole schedule is clean.

▶ Run checks these sample cases. Submit also runs hidden edge cases.

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

Expected output: false