Merge Overlapping Intervals
Updated
Problem statement
Given a list of closed integer intervals, merge every pair that overlaps and return the disjoint merged intervals ordered by start coordinate.
Closed intervals that share an endpoint overlap, so [1,4] and [4,5] merge into [1,5].
Function
mergeIntervals(intervals: int[][]) → int[][]Examples
Example 1
intervals = [[1,3],[2,6],[8,10],[15,18]]return = [[1,6],[8,10],[15,18]]The first two intervals overlap and merge.
Example 2
intervals = [[1,4],[4,5]]return = [[1,5]]Closed intervals sharing endpoint 4 overlap.
Constraints
0 <= intervals.length <= 100000.- Every interval has exactly two values and
-10^9 <= start <= end <= 10^9.
More Atlassian interview questions
- Tennis Court SchedulingPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Deterministic Word Guess SolverONSITE INTERVIEW · Seen Oct 2026
- Generate Word Guess FeedbackONSITE INTERVIEW · Seen Oct 2026
- Bounded Word Guess SolverONSITE INTERVIEW · Seen Oct 2026
- Word Guess Feedback ColorsONSITE INTERVIEW · Seen Oct 2026
- Implement a Rate LimiterPHONE SCREEN · Seen Oct 2026
- Longest Consistent Activity StreakPHONE SCREEN · Seen Sep 2026
- Music Player Operation SequencePHONE SCREEN · Seen Sep 2026
- Underline Shortest Unique SubstringsPHONE SCREEN · Seen Aug 2026
- Can a Dictionary Word Be Formed from Note Letters?PHONE SCREEN · Seen Feb 2026
Similar questions at other companies
- Merge IntervalsApple · OA · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
- Peak Chat Load Across AgentsCresta · PHONE SCREENCresta interview questions
- Meeting Rooms IIeBay · PHONE SCREENeBay interview questions
- Maximum Intervals Overlapping a Fixed-Length WindowBooking.com · ONSITE INTERVIEW
- Meeting Rooms IIByteDance · PHONE SCREENByteDance interview questions
- Majority Labels over Audio IntervalsNooks · PHONE SCREEN
- Meeting Rooms IISalesforce · ONSITE INTERVIEWSalesforce interview questions
- Generate Complete Inputs for a Supplied ClassifierGeneral Motors · ONSITE INTERVIEW
- Meeting Rooms IIUber · PHONE SCREENUber interview questions
- Merge IntervalsSafe Security · ONSITE INTERVIEW