Merge Sort
Easy Accuracy: 41.46% Submissions: 42044 Points: 2

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

Example 1:

Input:
5
4 1 3 9 7

Output: 
1 3 4 7 9

Example 2:

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

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

Your 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. The range [l,m] and [m+1,r] are already sorted.

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

Constraints:
1 <= N <= 105

1 <= arr[i] <= 103

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Output Window