Merge Overlapping Intervals
Updated
Problem statement
Given an array intervals, where intervals[i] = [start, end] is a closed interval, merge every pair of intervals that overlaps.
Return the non-overlapping merged intervals sorted by ascending start value.
Intervals that share an endpoint overlap. For example, [1, 4] and [4, 6] merge into [1, 6].
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 become [1, 6]. The other two intervals stay separate.
Example 2
intervals = [[1,4],[4,5]]return = [[1,5]]The intervals share endpoint 4, so they overlap under the closed-interval rule.
Example 3
intervals = [[5,7],[1,10],[2,3]]return = [[1,10]]The interval [1, 10] contains both other intervals, even though the input is not sorted.
Constraints
1 <= intervals.length <= 10^5.intervals[i].length == 2.-10^9 <= intervals[i][0] <= intervals[i][1] <= 10^9.
More Rippling Phone Screen questions
- Filter, Sort, and Deduplicate Scheduled TasksPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Stateful Log Transform and SearchPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Dependency-Aware Task SchedulerPHONE SCREEN · Seen Nov 2026
- Delivery Cost Tracker with Effective-Dated RatesPHONE SCREEN · Seen Nov 2026
- Camel CardsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best and Worst Camel Card CompletionsPHONE SCREEN · Seen Nov 2026
- Corporate Card Expense RulesOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- In-Memory Priority Task SchedulerPHONE SCREEN · Seen Oct 2026
- Limit an Organization Tree's HeightPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Median Across N Sorted ArraysPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Merge IntervalsApple · OA · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
- Merge Overlapping IntervalsAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian 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
Interview reports that mention this question
- Rippling No-Level Older Reports: 31 Experiences (Part 6 of 6)
- Rippling Delivery Cost Screen: 21 Experiences (Part 2 of 12)
- Rippling New Grad SDE Interviews: 11 Experiences
- Rippling Intern Onsite Interviews: 18 Experiences (Part 4 of 5)
- Rippling SWE Intern Interviews: 101 Experiences (Part 1 of 5)
- Rippling Full-Time SWE Interviews: 224 Experiences (Part 1 of 12)