Count how many indices can be removed so the remaining array has equal sums at even and odd positions.
You are given an integer array nums. In one move, you may remove exactly one element from the array.
After removing an element at index i, all elements to the right shift left, which changes the parity of their positions. An array is considered fair if the sum of elements at even indices equals the sum of elements at odd indices.
Return the number of indices whose removal makes the array fair.
Input Format
- An integer array
nums. - The array is 0-indexed.
Output Format
- Return an integer: the number of indices
isuch that removingnums[i]makes the array fair.
Constraints
1 <= nums.length <= $10^{5}$1 <= nums[i] <= $10^{4}$- Use 64-bit arithmetic if needed for intermediate sums.
Example 1
Input
nums = [2,1,6,4]
Output
1
Explanation
Removing index 1 leaves [2,6,4]. The even-index sum is 2 + 4 = 6 and the odd-index sum is 6, so the array is fair.
Example 2
Input
nums = [1,1,1]
Output
3
Explanation
Removing any index leaves a two-element array with equal even and odd sums: [1,1].
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.