Skip to content

Practice Make Array Elements Equal to Zero

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#3354
LeetCode Problem

Make Array Elements Equal to Zero

Problem Statement

Given nums, choose an index initially containing zero and an initial direction, left or right. While the current index is in bounds, a zero causes one step in the current direction. A positive value is decreased by one, then the direction is reversed and one step is taken. Stop after leaving the array. Count the initial index-and-direction choices for which every array value is zero when the process stops.

Source: Make Array Elements Equal to Zero on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

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

# Example 2

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

Constraints

1 <= nums.length <= 100
0 <= nums[i] <= 100
There is at least one element i where nums[i] == 0.

Related LeetCode Problems

Practice more problems similar to Make Array Elements Equal to Zero.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.