Description
Solutions
Merge Intervals
🤘 INTERN

Given a collection of time intervals, [start, end], merge and return the overlapping intervals sorted in ascending order of their start times.

Function Description

Complete the function getMergedIntervals in the editor below.

getMergedIntervals has the following parameters:

  1. int intervals[[n][2]]: the time intervals

Returns

int[][2]: the merged intervals in sorted order

Example 1:

Input:  intervals = [[7, 7], [2, 3], [6, 11], [1, 23]]
Output: [[1, 3], [6, 11]]
Explanation:
an educated guess -

The interval [1, 2] merges with [2, 3] while [7, 7] merges with [6, 11]. There are no more overlapping intervals. The answer is [[1, 3], [6, 11]].

Constraints:
  • 1 ≤ n ≤ 10^5
  • 1 ≤ intervals[i][2] ≤ 10^9
  • intervals[i][0] ≤ intervals[i][1] for all i.
Thumbnail 0
Testcase

Result
Case 1

input:

output: