FastPrepFastPrep
Problem Brief

Merge Intervals

INTERNOA

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

1Example 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

Limits and guarantees your solution can rely on.

  • 1 ≤ n ≤ 10^5
  • 1 ≤ intervals[i][2] ≤ 10^9
  • intervals[i][0] ≤ intervals[i][1] for all i.
  • public int[][] getMergedIntervals(int[][] intervals) {
      // write your code here
    }
    
    Input

    intervals

    [[7, 7], [2, 3], [6, 11], [1, 23]]

    Output

    [[1, 3], [6, 11]]

    Sign in to submit your solution.