Merge Intervals
medium
1. Question will be provided with "n" Intervals. An Interval is defined as (sp,ep) i.e. sp --> starting point & ep --> ending point of an Interval (sp/ep are inclusive). Some Intervals may or maynot overlap eachother. 2. Intervals[i] = [startingPoint,endingPoint] Task is to "Merge all Overlapping Intervals". Example 1 : Input : [[1,3],[2,4],[6,8],[10,14],[7,9]] Output : [[1,4],[6,9],[10,14]] Example 2 : Input : [[1,3],[3,15],[6,8],[10,14],[7,9]] Output : [[1,15][3,15]] Example 3 : Input : [[1,3],[5,8],[10,19],[15,20],[9,9]] Output : [[1,3],[5,8],[9,9],[10,20]]
Constraints
1. sp(Starting point) <= ep(Ending Point) 2. input is unsorted 3. 0 < n(Number of Intervals) <= 10^4
Format
Input
n (Representing number of Intervals) sp_1 ep_1 sp_2 ep_2 sp_3 ep_3 ... till "n" Intervals Note : 1. sp_1 means starting point for interval 1 , ep_1 means ending point for interval 1 2. Input format is handled for you.
Output
Output Format is handled for you.
Example
Sample Input
5
1 3
8 10
7 8
9 15
2 6
Sample Output
[[1, 6][7, 8][8, 15]]