Problem 351425 · easy · Level 03 Linear Management & Searching

One Person, No Clashes

intervals · sorting · adjacent comparison

Each meeting is [start, end): it occupies the times start <= t < end. Given an unsorted list meetings, return True if one person could attend all of them, i.e. no two meetings share any moment. A meeting that starts exactly when another ends is fine.

Examples

Input:  meetings = [[3, 12], [14, 18], [9, 15]]
Output: False
Explanation: [9, 15) overlaps both of the others.
Input:  meetings = [[11, 16], [6, 8], [8, 11]]
Output: True
Explanation: 6-8, 8-11, 11-16 follow each other back to back.

Constraints

  • 0 <= len(meetings) <= 5 * 10**4, 0 <= start < end <= 10**9.
  • Intervals are half-open: [a, b) and [b, c) do not clash.
  • Target complexity: O(n log n).

Goals

  • Sort intervals by start so that only neighbours need comparing
  • Apply the half-open rule so meetings that touch do not clash
Starting Python…