easyArrayPrefix SumSimulation 0 views

Make Array Elements Equal to Zero

You are given an integer array nums.

You are given an integer array nums.

Start by selecting a starting position curr such that nums[curr] == 0, and choose a movement direction of either left or right.

After that, you repeat the following process:

A selection of the initial position curr and movement direction is considered valid if every element in nums becomes 0 by the end of the process.

Return the number of possible valid selections.

Make Array Elements Equal to Zero diagram

Example 1

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

Output: 2

Explanation: The only possible valid selections are the following:

Example 2

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

Output: 0

Explanation: There are no possible valid selections.

Constraints

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

Hints

Companies

No companies reported yet.

Discussion

Sign in to join the discussion.

Loading discussion...

Test results

No test cases yet.