29. Sort an Array Into a Wave
EasySorting
Rearrange nums into a wave where a[0] ≥ a[1] ≤ a[2] ≥ a[3] ≤ …. Many waves are possible, so produce this specific one: sort the numbers ascending, then swap the elements at positions (0, 1), (2, 3), (4, 5), and so on. Return the new array.
Example 1
Input: nums = [3, 6, 5, 10, 7, 20] Output: [5, 3, 7, 6, 20, 10]
Constraints
0 ≤ nums.length ≤ 10⁵