FastPrepMerge Intervals

Merge Intervals

JP Morgan Chase logoJP Morgan Chase● EasyINTERNOA
Learn

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 JP Morgan Chase problems

See JP Morgan Chase hiring insights
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…