Merge Intervals
Updated
Problem statement
Given an array of closed intervals where intervals[i] = [start_i, end_i], merge every pair of overlapping intervals.
Return the non-overlapping intervals that cover every input interval, sorted by start value. Intervals that share an endpoint are considered overlapping.
Function
mergeIntervals(intervals: int[][]) → int[][]Examples
Example 1
intervals = [[1,3],[2,6],[8,10],[15,18]]return = [[1,6],[8,10],[15,18]]Intervals [1,3] and [2,6] overlap, so they merge into [1,6].
Example 2
intervals = [[1,4],[4,5]]return = [[1,5]]The intervals share endpoint 4, so they merge.
Example 3
intervals = [[8,10],[1,4],[2,3],[15,18],[6,9],[3,7],[17,20],[12,12]]return = [[1,10],[12,12],[15,20]]After sorting, the first five intervals form one overlap chain. The point interval remains separate, and the last two intervals merge.
Constraints
1 <= intervals.length <= 10000intervals[i].length == 20 <= start_i <= end_i <= 10000
More Zscaler interview questions
- Rate Limiter with Hourly and Daily Effort QuotasPHONE SCREEN · Seen Jul 2026
- Merging PalindromesPHONE SCREEN · Seen Sep 2024
- Find the Element With Odd FrequencyPHONE SCREEN · Seen Jun 2024
- Sum of Divisors of the Array GCDPHONE SCREEN · Seen Jun 2024
- Asteroid CollisionONSITE INTERVIEW · Seen Sep 2024
- Check Whether a Byte Is NonzeroONSITE INTERVIEW · Seen Sep 2024
- Count Vowel PermutationsONSITE INTERVIEW · Seen Sep 2024
- Longest Common Subsequence LengthONSITE INTERVIEW · Seen Jun 2024
- Run-Length EncodingONSITE INTERVIEW · Seen Jun 2024
- How Many Sentences? 🌿OA · Seen Mar 2024
Similar questions at other companies
- Total Years of Work ExperienceLinkedIn · PHONE SCREENLinkedIn interview questions
- Meeting RoomsByteDance · PHONE SCREENByteDance interview questions
- Meeting RoomsGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
- Merge IntervalsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
- Minimum Number of ChairsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Meeting Room Request FeasibilityApple · PHONE SCREENApple interview questions
- Meeting RoomsChainalysis · PHONE SCREENChainalysis interview questions
- Highlight and Rank Overlapping CitationsHarvey · PHONE SCREEN · ONSITE INTERVIEWHarvey interview questions
- Merge Overlapping IntervalsAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
- Peak Chat Load Across AgentsCresta · PHONE SCREENCresta interview questions