Timer is Running

The task is to complete merge() function which is used to implement Merge Sort.

First line of the input denotes number of test cases 'T'. First line of the testcase is the size of array and second line consists of array elements separated by space.

Sorted array in increasing order is displayed to the user.

User Task:
You don't need to take the input or print anything. Your task is to complete the function merge() which takes the array arr[], the starting position of the first array (l),  the ending position of the first array (m) and the ending position of the second array (r) as its inputs and modifies the array arr[] such that it is sorted from position l to position r. 

Expected Auxiliary Space: O(n)
Expected Time Complexity: O(n)  (for the merge() function) 

1 <= T <= 50
1 <= N <= 105

1 <= arr[i] <= 103

4 1 3 9 7
10 9 8 7 6 5 4 3 2 1

1 3 4 7 9
1 2 3 4 5 6 7 8 9 10

Testcase 1:
The array after performing mergesort is: 1 3 4 7 9.


** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Amit Khandelwal
Author: kartik

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.