Skip to content

Practice Merge Intervals

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#56
LeetCode Problem

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.

Source: Merge Intervals on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
intervals = [[1,3],[2,6],[8,10],[15,18]]
Output
[[1,6],[8,10],[15,18]]

# Example 2

Input
intervals = [[1,4],[4,5]]
Output
[[1,5]]

Constraints

1 <= intervals.length <= 10^4
intervals[i].length == 2
0 <= start_i <= end_i <= 10^4

Related LeetCode Problems

Practice more problems similar to Merge Intervals.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.