All problems
Wiggle Sort Check
Problem
Return True if nums already satisfies the wiggle pattern nums[0] <= nums[1] >= nums[2] <= nums[3] and so on.
Compare each adjacent pair with the required direction based on index parity. Lists of length 0 or 1 are trivially wiggle sorted.
Hint
Odd positions must be local maxima and even positions must be local minima.
Test cases
case 1
in: [[1,2,3]]
expected: false
case 2
in: [[1,3,2]]
expected: true
case 3
in: [[1,2,1,2]]
expected: true
case 4
in: [[1,2,3,4]]
expected: false
case 5
in: [[]]
expected: true
case 6
in: [[1]]
expected: true
Starter codePython
def is_wiggle_sorted(nums):
# Your code here
pass6 test cases · run your code against them in the editor