FastPrepMerge Overlapping Intervals
Problems/Merge Overlapping Intervals

Merge Overlapping Intervals

Adobe logoAdobe● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem merges a list of closed intervals, in any order, into the smallest set of intervals that covers the same points, sorted by start. An Adobe Computer Scientist II (backend) report opens its live coding round, after an online test, with a twist on the well-known interval-merging question, but does not say what the twist was.

Our choices: the plain merging task (the twist is unknown), intervals that only touch also merge, unsorted input, at most 2000 intervals with ends from 0 to 10^9, and new examples.

The judged task matches the report at about 60%.

You are given a list of closed intervals [start, end] in any order. Two intervals overlap if they share at least one point; intervals that only touch at an end, like [1, 5] and [5, 6], also count.

Merge every group of overlapping intervals (including chains, where A overlaps B and B overlaps C) into one interval that covers the group. Return the merged intervals sorted by start.

Function

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

Examples

Example 1

intervals = [[9,12],[2,5],[4,7],[14,14]]return = [[2,7],[9,12],[14,14]]

[2, 5] and [4, 7] overlap on 4 to 5, so they become [2, 7]. [9, 12] and [14, 14] touch nothing else. Sorted by start: [2, 7], [9, 12], [14, 14].

Example 2

intervals = [[5,6],[1,5],[6,10]]return = [[1,10]]

[1, 5] and [5, 6] share the point 5, and [5, 6] and [6, 10] share 6, so all three join into [1, 10]. Intervals that only touch at an end point count as overlapping.

Example 3

intervals = [[3,20],[4,8],[10,11]]return = [[3,20]]

[4, 8] and [10, 11] lie inside [3, 20], so the answer is just [3, 20].

Constraints

  • 1 <= intervals.length <= 2000
  • each intervals[i] = [start, end] with 0 <= start <= end <= 10^9

More Adobe problems

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
All Adobe interview questionsSee Adobe hiring insights
Saved
public int[][] mergeIntervals(int[][] intervals) {
    // Write your code here.
}
Checking account…