Ninja has been given an arbitrary array of integers of size ‘N'. You can think of the array as the concatenation of two individually sorted arrays in non-decreasing order. Ninja needs to sort the entire array in ascending order.
Can you help Ninja to sort the array?
Note :Both the partitions need not be of the same size.
The first line of the input contains a single integer 'T', representing the number of test cases.
The first line of each test case consists of a single integer, representing the size of the array.
The second line of each test case contains 'N' space-separated integers, denoting the elements of the array.
Output Format :
For each test case, print the elements of the array in the space-separated form which is sorted in non-decreasing order.
Note :
You do not need to print anything. It has already been taken care of. Just implement the given function. Also, you need to update the given array in place.
1 <= T <= 100
1 <= N <= 10^4
1 <= ARR[i] <= 10^9
Time Limit: 1 sec
1
6
7 10 12 3 4 5
3 4 5 7 10 12
The given array can be broken into two sorted partitions as P1={7, 10, 12} and P2={3, 4, 5}. After sorting the entire array in ascending order, we get {3, 4, 5, 7, 10, 12}.
1
5
1 5 10 2 6
1 2 5 6 10
Can we use the merge function of MergeSort?
O(N), where ‘N’ is the number of elements in the array.
As we are using a two-pointer approach to traverse over the array.
O(N), where ‘N’ is the number of elements in the array.
As we are using extra space for the temporary array.