FastPrepMerge Intervals
Problems/Merge Intervals

Merge Intervals

Bloomberg LP logoBloomberg LP● MediumFULLTIMENEW GRADOAPHONE SCREENONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The judged core task matches the original report at about 99%.

Given an array intervals where intervals[i] = [start_i, end_i], merge every pair of overlapping closed intervals. Return the non-overlapping intervals that cover exactly the same values, ordered by increasing start.

Function

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

Examples

Example 1

intervals = [[1,3],[2,6],[8,10],[15,18]]return = [[1,6],[8,10],[15,18]]

The closed intervals [1,3] and [2,6] overlap, so they merge into [1,6].

Example 2

intervals = [[1,4],[4,5]]return = [[1,5]]

Closed intervals that share an endpoint overlap.

Constraints

  • 1 <= intervals.length <= 10^4
  • intervals[i].length = 2
  • 0 <= start_i <= end_i <= 10^4
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public int[][] merge(int[][] intervals) {
        // write your code here
    }
}
Checking account…