DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
medium
Array

Merge Intervals

**Problem Statement:** Given an array of `intervals` where `intervals[i] = [starti, endi]`, merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input. **Hint / Expected Approach:** Sort by start, merge overlapping **Edge Cases to Consider:** - (1) No overlapping intervals - (2) All intervals overlap into one - (3) Single interval

Examples

Example 1
Input: [[1,3],[2,6],[8,10],[15,18]]
Output: [[1,6],[8,10],[15,18]]
Example 2
Input: [[1,4],[4,5]]
Output: [[1,5]]
Example 3
Input: [[1,4],[2,3]]
Output: [[1,4]]

Constraints

  • ▪1 <= nums.length <= 10^4
  • ▪-10^9 <= nums[i] <= 10^9
  • ▪Time complexity should be O(n) or O(n log n)

Watch Out For Edge Cases

  • ▪No overlapping intervals
  • ▪All intervals overlap into one
  • ▪Single interval
Frequently Asked At
GoogleAmazonMicrosoftMetaAdobeUberFlipkart