Merge Overlapping Intervals
Updated
Problem statement
You are given integer intervals [start, end], each including both endpoints. Merge each group of overlapping intervals into one interval. Intervals that share an endpoint overlap.
Return the merged intervals in increasing start order. An empty input returns an empty list. For this exercise, use the conventional closed-interval interpretation and the bounded array interface below.
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.
Example 2
intervals = [[1,4],[4,5]]return = [[1,5]]Endpoint contact is included for closed intervals.
Example 3
intervals = []return = []No intervals need to be merged.
Constraints
0 <= intervals.length <= 2000.- Every row contains two integers with
-10^6 <= start <= end <= 10^6.
More ByteDance Onsite Interview questions
- Search a Row- and Column-Sorted MatrixONSITE INTERVIEW · Seen Nov 2026
- Alien DictionaryPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lexicographically Smallest Topological OrderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Implement Multi-Head AttentionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Dynamic Median with Additions and DeletionsONSITE INTERVIEW · Seen Oct 2026
- Serialize and Deserialize a String Key-Value StoreONSITE INTERVIEW · Seen Oct 2026
- Binary Tree Maximum Path SumONSITE INTERVIEW · Seen Oct 2026
- Tic-Tac-Toe Move WinnersONSITE INTERVIEW · Seen Oct 2026
- Kth Largest Element without a HeapONSITE INTERVIEW · Seen Oct 2026
- Least Recently Used CachePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Generate All Permutations of a NumberFleetx · ONSITE INTERVIEW
- Rank Word-Translation Hints from Sentence TranslationsDuolingo · PHONE SCREEN · ONSITE INTERVIEWDuolingo interview questions
- Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
- Fair Capped Money DistributionGusto · PHONE SCREEN · ONSITE INTERVIEWGusto interview questions
- Group AnagramsAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
- Merge IntervalsApple · OA · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
- Merge Sorted Squares of Two ArraysWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
- Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Filter, Sort, and Deduplicate Scheduled TasksRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Merge Overlapping IntervalsAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
ByteDance interview experiences
- ByteDance TikTok USDS SWE Intern Interview: 1 Experience
- ByteDance MLE New Grad Interviews: 1 Experience
- ByteDance Security SRE Intern Phone Screens: 1 Experience
- ByteDance USDS New Grad SWE Phone Screen: 1 Experience
- ByteDance New Grad Data Engineer Video Interviews: 1 Experience
- ByteDance Trust & Safety Research Scientist Intern: 1 Experience