Ways to Make a Fair Array
You are given an integer array nums. You can choose exactly one index (0-indexed) and remove the element. Notice that the index of the elements may change after the removal.
For example, if nums = [6,1,7,4,1]:
- Choosing to remove index
1results innums = [6,7,4,1]. - Choosing to remove index
2results innums = [6,1,4,1]. - Choosing to remove index
4results innums = [6,1,7,4].
An array is fair if the sum of the odd-indexed values equals the sum of the even-indexed values.
Return the number of indices that you could choose such that after the removal, nums is fair.
Example 1
Input
nums = [2,1,6,4]Output
1Only removing index 1 makes the even-indexed sum equal to the odd-indexed sum, so there is 1 removable index.
Example 2
Input
nums = [1,1,1]Output
3You can remove any index and the remaining array is fair.
Constraints
- 1 <= nums.length <= 10^5
- 1 <= nums[i] <= 10^4