Merge Sort
Mediumjavapythonccppjavascript
Sort an integer array in ascending order using the Merge Sort algorithm — split the array, sort each half, then merge the sorted halves. The judge checks the final sorted output.
Input Format
The first line contains an integer N. The second line contains N space-separated integers.
Output Format
Print the N integers in ascending order, separated by single spaces, on one line.
Example 1
Input
5 5 3 8 1 2
Output
1 2 3 5 8
Explanation: Halves are sorted recursively and merged.
- 1 <= N <= 100000
- -1000000000 <= A[i] <= 1000000000