LeetCode 252 Meeting Rooms - Example and Complexity Analysis

Walkthrough and analysis

Trace intervals = [[7,10],[2,4],[5,6]].

Sort by start: [[2,4],[5,6],[7,10]].

Check pairs:

  • [2,4] and [5,6]: 5 >= 4. No overlap.
  • [5,6] and [7,10]: 7 >= 6. No overlap.

All meetings can be attended. Return true.

Trace [[0,30],[5,10],[15,20]]. After sorting: [[0,30],[5,10],[15,20]].

  • [0,30] and [5,10]: 5 < 30. Overlap! Return false.

O(nlogn)O(n \log n) time for sorting. O(1)O(1) extra space (or O(n)O(n) depending on sort).