Tap here to switch tabs
Problem
Submissions

Problem: Make Array Elements Equal to Zero

Try to solve the Make Array Elements Equal to Zero problem.

Statement

You are given an integer array nums.

You start by picking a starting position curr such that nums[curr] = 0 and choosing a direction: left or right.

The process then proceeds as follows:

  • If curr goes out of bounds, meaning curr <0< 0 or curr ≥\geq nums.length, the process finishes.

  • If nums[curr] = 0, continue moving in the current direction by one index (decrement curr if moving left, or increment curr if moving right).

  • If nums[curr] > 0, decrease nums[curr] by 11, reverse the current direction, and take one step in the new direction.

A choice of starting index curr and initial direction is considered valid if every element in nums becomes 00 when the process finishes.

Return the total number of valid selections.

Constraints:

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

  • 0≤0 \leq nums[i] ≤100\leq 100

  • There is at least one element i where nums[i] == 0.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Make Array Elements Equal to Zero

Try to solve the Make Array Elements Equal to Zero problem.

Statement

You are given an integer array nums.

You start by picking a starting position curr such that nums[curr] = 0 and choosing a direction: left or right.

The process then proceeds as follows:

  • If curr goes out of bounds, meaning curr <0< 0 or curr ≥\geq nums.length, the process finishes.

  • If nums[curr] = 0, continue moving in the current direction by one index (decrement curr if moving left, or increment curr if moving right).

  • If nums[curr] > 0, decrease nums[curr] by 11, reverse the current direction, and take one step in the new direction.

A choice of starting index curr and initial direction is considered valid if every element in nums becomes 00 when the process finishes.

Return the total number of valid selections.

Constraints:

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

  • 0≤0 \leq nums[i] ≤100\leq 100

  • There is at least one element i where nums[i] == 0.