AAlgoLab
ALG-M007MediumIntervals

Consolidate Time Windows

Merge all closed intervals that overlap or touch at an endpoint. Return merged [start,end] pairs sorted by starting coordinate.

Contract

input intervals: integer[][]
return integer[][]

Constraints

  • • Each interval has exactly two integers with start <= end
  • • 0 <= intervals <= 10000

Examples

Example 1
intervals = [[1, 3], [2, 6], [8, 10]]
→ [[1, 6], [8, 10]]
Example 2
intervals = [[1, 4], [4, 5]]
→ [[1, 5]]

5 judge tests (2 shown above). Target complexity: O(n log n).