Wave Array
Submissions: 22709   Accuracy:


  Difficulty: Easy   Marks: 2
Associated Course(s):   Interview Preparation

Given a sorted array arr[] of non-repeating integers without duplicates. Sort the array into a wave-like array and return it. In other words, arrange the elements into a sequence such that a1 >= a2 <= a3 >= a4 <= a5..... (considering the increasing lexicographical order).

The first line contains an integer T, depicting total number of test cases. T testcases follow. The first line of each testcase contains an integer N depicting the size of the array. The second line contains N space separated elements of the array.

For each testcase, in a new line, print the array into wave-like array.

1 ≤ T ≤ 100
1 ≤ N ≤ 106
0 ≤ A[i] ≤107

1 2 3 4 5
2 1 4 3 5

Testcase 1:
Array elements after sorting it in wave form are 2 1 4 3 5 .


** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Harshit Sidhwa
Author: shef5

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.