Practice Decrease Elements To Make Array Zigzag
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
In one move, decrease any element of nums by 1. A zigzag array must follow one of two strict patterns: every even-indexed value is greater than its existing neighbors, or every odd-indexed value is greater than its existing neighbors. Indices start at 0. Return the fewest moves needed to obtain either pattern.
Source: Decrease Elements To Make Array Zigzag on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
nums = [1,2,3]
2
# Example 2
nums = [9,6,1,6,2]
4
Constraints
Related LeetCode Problems
Practice more problems similar to Decrease Elements To Make Array Zigzag.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.