You are given an integer array nums.
You must begin at some index curr where the value is already 0, and choose an initial motion direction: either left or right.
From there, follow this repeating procedure:
If curr moves outside the array, the process stops.
If nums[curr] == 0, continue moving in the same direction by stepping to the next index.
If nums[curr] > 0, decrease that value by 1, reverse your movement direction, and then take one step in the opposite direction.
A starting index (with an associated direction) is valid if this process eventually turns every element in the array into zero.
Return the total number of valid (index, direction) pairs.
Input: nums = [1, 0, 1, 0]
Output: 0
Explanation:
Even though there are two zeros to start from, no direction choice allows all numbers to reach zero simultaneously.
Input: nums = [0, 2, 0]
Output: 2
Explanation:
Starting at index 0 going right, or starting at index 2 going left, both fully reduce the array to all zeros. Other choices fail.
Accepted:
Submission: