Merge Intervals Problem Overview
The "Merge Intervals" problem, commonly tagged with Array, Sorting, and Intervals, asks you to merge overlapping intervals from a given list and return non-overlapping intervals sorted by start time. This is LeetCode 56, frequently appearing in Netflix and other tech interviews.[2][5]
Full Problem Statement
Given an array of intervals where intervals[i] = [start_i, end_i], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.
Intervals are considered overlapping if they have any points in common, including touching endpoints (e.g., and merge into ).[1][3][5][7][2]
Input/Output Examples
Example 1:
Input: intervals = [[1,3],[2,6],[8,10],[15,18]]
Output: [[1,6],[8,10],[15,18]]
Explanation: and overlap to form; others remain separate.[3][5][6][1][2]
Example 2:
Input: intervals = [[1,4],[4,5]]
Output: [[1,5]]
Explanation: Intervals touch at 4 and merge.[5]
Example 3:
Input: intervals = [[1,4],[0,4]]
Output: [[0,4]]
Explanation: Full overlap merges into widest range.[5]
Constraints
0 <= intervals.length <= 10^4intervals[i].length == 20 <= start_i <= end_i <= 10^4