You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This program accepts an array of unsorted numbers and
sorts the array such that arr[0]<arr[1]>arr[2]<arr[3]...
arr is sorted and stored in second array res
res is partitioned into two such that left sub-array
contains elements less than the elements in right sub-array
Elements in the left sub-array are added to the even indices of arr
Elements in the right sub-array are added to the odd indices of arr
Sample input:1 3 2 2 3 1
Sample output: [2,3,1,3,1,2]
Sample input:1 4 6 2 3 7 9 2 1 0
Sample Output: [2, 9, 2, 7, 1, 6, 1, 4, 0, 3]
Time Complexity: O(N log N) (Sorting takes O(N logN) and traversal takes O(N))
Space Complexity: O(N) (New array to store the wiggle sorted elements)
The text was updated successfully, but these errors were encountered: