Merge Sort Problem Statement

Given a sequence of numbers ARR, your task is to return a sorted sequence of ARR in non-descending order using the merge sort algorithm.

Explanation:

The Merge Sort Algorithm is a Divide and Conquer based method which divides the input array into two parts until the size of the array is 1. Then, it merges the two sorted arrays to create a fully sorted array.

Input:

The first line of input contains an integer 'T' denoting the number of test cases.
The next 2*T lines represent the 'T' test cases.
The first line of each test case contains an integer 'N' which denotes the size of 'ARR'.
The second line of each test case contains 'N' space-separated elements of 'ARR'.

Output:

For each test case, print the numbers in non-descending order.

Example:

Input:
T = 1
N = 5
ARR = [4, 1, 5, 2, 3]
Output:
1 2 3 4 5

Constraints:

  • 1 <= T <= 50
  • 1 <= N <= 104
  • -109 <= arr[i] <= 109

Note:

You are not required to print the expected output; it has already been taken care of. Just implement the function.

Be the first one to answer
Add answer anonymously...
Oracle Member Technical Staff Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter