Merge Intervals
Updated
Problem statement
Given an array of closed integer intervals intervals, where each interval is [start, end], merge every pair of overlapping intervals.
Closed intervals that touch at one endpoint overlap. Return disjoint intervals that represent the same union, sorted by increasing start value.
Function
mergeIntervals(intervals: int[][]) → int[][]Examples
Example 1
intervals = [[1,3],[2,6],[8,10],[10,18]]return = [[1,6],[8,18]]Intervals [1,3] and [2,6] overlap. Intervals [8,10] and [10,18] touch at endpoint 10, so they also merge.
Example 2
intervals = []return = []An empty input has an empty union.
Constraints
0 <= intervals.length <= 200000- Every row of
intervalshas exactly two integers[start, end]. -10^9 <= start <= end <= 10^9
More OneTrust interview questions
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
- Meeting Rooms IIByteDance · PHONE SCREENByteDance interview questions
- Majority Labels over Audio IntervalsNooks · PHONE SCREEN
- Meeting Rooms IIUber · PHONE SCREENUber interview questions
- Merge IntervalsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Merge Overlapping IntervalsFurtherAI · PHONE SCREEN
- Peak Resource Usage Across Weighted IntervalsTekion · PHONE SCREENTekion interview questions