Input: arr[]= {7, 6, 8, 9, 0, 1, 2, 2, 1, 8, 9, 6, 7}, K = 6
Output: 9 9 8 8 7 7 0 1 1 2 2 6 6
Explanation:
The first K (= 6) elements of the sorted array are {9, 9, 8, 8, 7, 7}, which are in descending order.
The last N - K (= 6) elements of the sorted array are {0, 1, 1, 2, 2, 6, 6}, which are in ascending order.
Therefore, the required output is 9 9 8 8 7 7 0 1 1 2 2 6 6
Input: arr[]= {65, 34, 54, 56, 75, 34, 54, 65, 56, 75, 15}, K = 5
Output: 75 75 65 65 56 56 15 34 34 54 54