Tap here to switch tabs
Problem
Submissions

Problem: Decrease Elements To Make Array Zigzag

med
30 min
Try to solve the Decrease Elements To Make Array Zigzag problem.

Statement

Given an array of integers nums, in each move, you can select any element and reduce its value by 11.

An array nums is a zigzag array if either of the following conditions is satisfied:

  • Every even indexed element is strictly greater than its adjacent elements (that is, for every even index ii, nums[i] > nums[i - 1] and nums[i] > nums[i + 1], whenever the adjacent elements exist).

  • Every odd indexed element is strictly greater than its adjacent elements (that is, for every odd index ii, nums[i] > nums[i - 1] and nums[i] > nums[i + 1], whenever the adjacent elements exist).

Return the minimum number of moves needed to transform nums into a zigzag array.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • 1≤1 \leq nums[i] ≤1000\leq 1000

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Decrease Elements To Make Array Zigzag

med
30 min
Try to solve the Decrease Elements To Make Array Zigzag problem.

Statement

Given an array of integers nums, in each move, you can select any element and reduce its value by 11.

An array nums is a zigzag array if either of the following conditions is satisfied:

  • Every even indexed element is strictly greater than its adjacent elements (that is, for every even index ii, nums[i] > nums[i - 1] and nums[i] > nums[i + 1], whenever the adjacent elements exist).

  • Every odd indexed element is strictly greater than its adjacent elements (that is, for every odd index ii, nums[i] > nums[i - 1] and nums[i] > nums[i + 1], whenever the adjacent elements exist).

Return the minimum number of moves needed to transform nums into a zigzag array.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • 1≤1 \leq nums[i] ≤1000\leq 1000