Page cover

Wavy Array

Given an array of integers, 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.....

Using Sorting and Swap Alternate (Most Optimal)

Time Complexity: O(nlogn)O(n \log n)

Space Complexity: O(1)O(1)

Last updated