| Topic | Difficulty | Companies |
|---|---|---|
| Stack and Queue | MEDIUM | Amazon Google |
You will be given a set of intervals in the form of a 2-D array arr, write a program to merge all the overlapping intervals, and return a 2-D array.
Problem Note:
intervals consisting of r rows and 2 columns.Example 1
Input: [[1, 5], [2, 3], [4, 8], [9, 10]]
Output: [[1, 8], [9, 10]]
Explanation: In the above example, [[1, 5], [2, 3], [4, 8]] will be merged in the interval [1, 8], while [9, 10] is a separte interval. Thus we get [[1, 8], [9, 10]] as output.
Example 2
Input: [[1, 4], [5, 8], [8, 10], [12, 15]]
Output: [[1, 4], [5, 10], [12, 15]]
Explanation: In the above example, [1, 4] is a separte interval, [[5, 8], [8, 10]] will be merged in the interval [5, 10], and [12, 15] is a separate interval. Thus we get [[1, 4], [5, 10], [12, 15]] as output.
Example 3
Input: [[3, 8], [4, 6], [6, 10]]
Output: [[3, 10]]
Explanation: In the above example, [[3, 8], [4, 6], [6, 10]] will be merged in a single interval [3, 10]. Thus we get [[3, 10]] as output.