Posted: 29 Jan, 2020
You are given a 2-dimensional array ‘Intervals’ containing a list of non-overlapping intervals sorted by their start time. You are given an interval ‘newInterval’. Your task is to insert the given interval at the correct position and merge all necessary intervals to produce a list with only mutually exclusive intervals.
Consider 'Intervals' = [[1, 3], [5, 7], [8, 12]], and 'newInterval' = [4, 6] The interval [4, 6] overlaps with [5, 7]. Therefore we can merge the intervals and produce an interval [4, 7]. Hence the answer [[1,3], [4,7], [8,12]]
The first line of the input contains a single integer, 'T,’ denoting the number of test cases. The first line of each test case contains a single integer, ‘N’, denoting the number of intervals. The following ‘N’ lines of the test case contain two space-separated integers, ‘Intervals[i]’ and ‘Intervals[i]’, denoting the start and the end of the ‘i-th’ interval. The last line of the test case contains two space-separated integers, ‘newInterval’ and ‘newInterval’, denoting the interval to be inserted into the list of intervals.
For each test case, print the intervals sorted by their start time. Each interval is to be printed in a separate line in a space-separated manner. Print the output of each test case in a separate line.
You do not need to print anything. It has already been taken care of. Just implement the function.
1 <= T <= 5 0 <= N <= 10^5 0 <= Intervals[i], Intervals[i] <= 10^10 0 <= newInterval, newInterval <= 10^10 Time Limit: 1 sec
Best time to buy and sell stock II
Posted: 5 Sep, 2022
Next Greater Element II
Posted: 9 Sep, 2022
Ninja And The Class Room
Posted: 19 Sep, 2022
Posted: 21 Oct, 2022
Find The Single Element
Posted: 30 Oct, 2022