Skip to content

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.

Medium#1144
LeetCode Problem

Decrease Elements To Make Array Zigzag

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

Input
nums = [1,2,3]
Output
2

# Example 2

Input
nums = [9,6,1,6,2]
Output
4

Constraints

1 <= nums.length <= 1000
1 <= nums[i] <= 1000

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.