BugForge
DSA

Merge Maintenance Windows

Mediumintervalssorting 00:00

Merge all overlapping maintenance windows [start, end] (inclusive; touching windows like [1,4] and [4,5] merge). Return them sorted by start.

Signature

mergeWindows(windows: int[][]) → int[][]
Example 1
windows = [[1,3],[2,6],[8,10],[15,18]]
output = [[1,6],[8,10],[15,18]]
[[1,6],[8,10],[15,18]]
Example 2
windows = [[1,4],[4,5]]
output = [[1,5]]
[[1,5]]

Constraints

  • 1 ≤ n ≤ 10^4
  • 0 ≤ start ≤ end ≤ 10^4
Run checks the examples. Submit runs every hidden test (16, including large inputs that catch slow solutions).