P14417 [GeeksforGeeks] Sort first half in ascending and second half in descending1714
普及-
题目描述

Given an array arr of n integers, sort the first half of the array in ascending order and second half in descending order.
Example 1:
Input:
n = 4
arr[] = {10, 20, 30, 40}
Output: 10 20 40 30
Example 2:
Input:
n = 9
arr[] = {5, 4, 6, 2, 1, 3, 8, 9, 7}
Output: 2 4 5 6 9 8 7 3 1
Your Task:
You don't need to read input or print anything. Your task is to complete the function customSort() which takes the array of integers arr and n as parameters and returns void. You need to change the array itself.
Expected Time Complexity: O(n*logn)
Expected Auxiliary Space: O(1)
Constraints:
1 <= n <= 10^{5}
1 <= arr[i] <= 10^{6}

输入格式

见题面

输出格式

见题面

样例输入
n = 4 arr[] = {10, 20, 30, 40}
样例输出
10 20 40 30