Amazon Online Assessment 2021 (OA) - Merge Intervals
Imagine being in charge of a big warehouse that's bustling with trucks coming in and going out all day; that's a lot of start times and end times to keep track of, isn't it? Here's a challenge that needs to be solved: There are several time periods, each marked by a 'start' and an 'end' time. Your task is to identify and merge all overlapping time periods, getting rid of any redundancies. When all is said and done, sort all the time periods in ascending order according to when they start. Simple enough, don't you think?
Input
intervals
: the time intervals
Output
the merged intervals in sorted order
Examples
Example 1:
Input:
intervals = [[7,7],[2,3],[6,11],[1,2]]
Output: [[1,3],[6,11]]
Explanation:
The interval [1,2]
merges with [2,3]
while [7,7]
merges with [6,11]
. There are no more overlapping intervals. The answer is [[1,3],[6,11]]
.