Merge Sort Task

Given a sequence of numbers, denoted as ARR, your task is to return a sorted sequence of ARR in non-descending order using the Merge Sort algorithm.

Example:

Explanation:
The Merge Sort algorithm is based on Divide and Conquer. It splits the input array into two parts, continuing until each part has a size of '1'. It then merges the sorted arrays to return one fully sorted array.
subsequence
The above illustration shows how merge sort works.

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, output the numbers in non-descending order.
Constraints:
  • 1 ≤ T ≤ 50
  • 1 ≤ N ≤ 10^4
  • -10^9 ≤ arr[i] ≤ 10^9
  • Time Limit: 1 sec
Note:
It is compulsory to use the 'Merge Sort' algorithm.
You are not required to print the expected output; it has already been taken care of. Just implement the function.
AnswerBot
2d

Implement Merge Sort algorithm to sort a sequence of numbers in non-descending order.

  • Divide the input array into two halves recursively until each part has a size of '1'.

  • Merge the sorted arrays to ret...read more

Help your peers!
Add answer anonymously...
Comviva Technology Software Developer 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