Problem · Intervals

Merge Intervals

Learn this problem
EasyJPMorgan ChaseINTERNOA

Problem statement

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

Function

getMergedIntervals(intervals: int[][]) → int[][]

Examples

Example 1

intervals = [[7, 7], [2, 3], [6, 11], [1, 2]]return = [[1, 3], [6, 11]]

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.
  • More JPMorgan Chase problems

    drafts saved locally
    public int[][] getMergedIntervals(int[][] intervals) {
      // write your code here
    }
    
    intervals[[7, 7], [2, 3], [6, 11], [1, 2]]
    expected[[1, 3], [6, 11]]
    checking account