β back to unit
Challenge
# sorting advanced
The Perfect Zigzag
The dance line must zigzag: up, down, up, down β every step changes direction, no repeats in a row. π
You get at least 2 nums with no equal neighbors. Print zigzag if the direction flips at every step (it may start going either up or down), otherwise no zigzag.
Example:
Input: nums = [1, 5, 2, 6, 3]
Output: zigzag
The direction flips every step β up (1β5), down (5β2), up (2β6), down (6β3) β never repeating.
π‘ need a hint?
sort-perfect-zigzag.pyπ given lines are locked β write your code in between
loading...