Merge Overlapping Intervals
L9 Hard Arrays & Hashing
Interval problems usually start by sorting by start time; then a careful merge walk keeps a live interval and extends it when the next one overlaps.
Given an array of intervals intervals where each is [start, end] (inclusive), merge all overlapping intervals and return the resulting array of non-overlapping intervals.
Examples
▸ intervals = [[1, 3], [2, 6], [8, 10], [15, 18]]
→ [[1, 6], [8, 10], [15, 18]]
▸ intervals = [[1, 4], [4, 5]]
→ [[1, 5]]