Consider an array that is divided into two parts and both of the parts are sorted individually. Given the mentioned array and the end index of the first part, merge them to create a sorted array. Update the same array with the merged elements. You can use extra auxiliary space.
Expected Time Complexity: O(n) where n denotes the size of the array.
Array: [1, 3, 5, 7, 9, 11, 0, 4, 6, 8]
End Index: 5
Array after merging: [0, 1, 3, 4, 5, 6, 7, 8, 9, 11]
First-line contains an integer ‘T’ denoting the number of test cases.
For each test case the input has two lines:
For each test case, the output has a line with n space-separated integers denoting the elements of the merged array.
2
10 5
1 3 5 7 9 11 0 4 6 8
8 3
3 3 9 11 1 3 3 4
0 1 3 4 5 6 7 8 9 11
1 3 3 3 3 4 9 11
1 <= T <= 100
1 <= n <= 104
0 <= endIndex < n
-105 <= array element <= 105