Wave sort

Given a random integer array, sort this array into a wave like pattern. In other words, arrange the elements as a0 >= a1 <= a2 >= a3 <= a4>= a5..... Try doing it in minimum change in the given array.

Change in the input array itself. You don't need to return or print elements.
Note : Don't sort the array.

Input format :

Line 1 : n (Array Size)

Line 2 : Array elements (separated by space)

Sample Input 1:
10
718 17 751 885 936 902 829 820 713 270
Sample Output 1:
718 17 885 751 936 829 902 713 820 270

Login to submit your solution

Fb dab53a1a64929320dc7425896aa73fd9e5512b6ab52e414ff5f3ebb5cecc73eb

Share Problem