Let’s say the list of intervals is: [[1,3], [5,7], [8,12]] and we need to insert the interval [4,6] into the list. [4,6] must be inserted in the second position. After insertion, since [4,6] overlaps with [5,7], we merge them into one interval [4,7]. So, our resulting list is: [[1,3], [4,7], [8,12]]
The first line of input contains an integer ‘T’ representing the number of test cases. The first of every test case contains the positive integer ‘N’ denoting the number of intervals present in the list. Next ‘N’ lines contain two space-separated integers, ‘start’ and ‘end’, denoting the starting and the ending point of the interval present in the list. The next line contains two space-separated integers, start and end, denoting the starting and the ending point of the interval which is to be inserted into the list.
For each test case, return the list after inserting the given interval.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10 1 <= N <= 5 * 10^4 1 <= start <= end <= 10^5 Time Limit: 1 sec
Merge Two Sorted Arrays Without Extra Space
Sort 0s, 1s, 2s