Merge Intervals Problem
Merge Intervals Problem — ExecCode Medium DSA Practice
Solve the Merge Intervals problem on ExecCode. Free online medium DSA practice in Intervals. Write and run code in Java, C++, Python — no signup required to run.
Problem description
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.
Examples
Input intervals = [[1, 3], [2, 6], [8, 10], [15, 18]]; Output [[1, 6], [8, 10], [15, 18]]. Input intervals = [[1, 4], [4, 5]]; Output [[1, 5]]. Input intervals = [[1, 4], [2, 3]]; Output [[1, 4]]
Constraints
1 ≤ intervals.length ≤ 10⁴ intervals[i].length == 2 0 ≤ starti ≤ endi ≤ 10⁴
Practice Merge Intervals free on ExecCode. Browse DSA problems, topic map, and placement guides.