Given an array of intervals where intervals[i] = [start_i, end_i]
, merge all overlapping intervals.
Rules:
Constraints:
Examples:
// Example 1:
console.log(
merge([
[1, 3],
[1, 5],
[6, 7],
]),
);
// Output: [[1,5],[6,7]]
// Explanation: First two intervals overlap
// Example 2:
console.log(
merge([
[1, 2],
[2, 3],
]),
);
// Output: [[1,3]]
// Explanation: Adjacent intervals merge