Merge Intervals
Try to solve the Merge Intervals problem.
We'll cover the following
Statement#
We are given an array of closed intervals, intervals, where each interval has a start time and an end time. The input array is sorted with respect to the start times of each interval. For example, intervals = is sorted in terms of start times , and .
Your task is to merge the overlapping intervals and return a new output array consisting of only the non-overlapping intervals.
Constraints:
-
intervals.length intervals[i].length- start time end time
Examples#
1 of 3
2 of 3
3 of 3
Understand the problem#
Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:
Merge Intervals
Given the below intervals, find the correct output after merging the overlapping intervals.
[ [1, 6], [2, 4] ]
[ [2, 4] ]
[ [1, 6] ]
[ [1, 6], [2, 4] ]
[ [2, 4], [1, 6] ]
Figure it out!#
We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.
Try it yourself#
Implement your solution in the following coding playground.
Solution: Insert Interval
Solution: Merge Intervals