Problem 351425 · easy · Phase 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 = [[0, 30], [5, 10], [15, 20]]
Output: False
Explanation: [0, 30) overlaps both of the others.
Input:  meetings = [[7, 10], [2, 4], [4, 7]]
Output: True
Explanation: 2-4, 4-7, 7-10 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…