Merge Intervals
Hard · Arrays
Write a function mergeIntervals that takes an array of intervals [start, end] (in any order) and merges all overlapping ones.
Intervals that only touch (like [1, 4] and [4, 5]) also merge. Return the merged intervals sorted by start. Do not change the input.
Next: Spiral Matrix