You are given an integer array&nbsp;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 1 results in nums = [6,7,4,1].
	Choosing to remove index 2 results in nums = [6,1,4,1].
	Choosing to remove index 4 results in nums = [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. 

&nbsp;
Example 1:

Input: nums = [2,1,6,4]
Output: 1
Explanation:
Remove index 0: [1,6,4] -&gt; Even sum: 1 + 4 = 5. Odd sum: 6. Not fair.
Remove index 1: [2,6,4] -&gt; Even sum: 2 + 4 = 6. Odd sum: 6. Fair.
Remove index 2: [2,1,4] -&gt; Even sum: 2 + 4 = 6. Odd sum: 1. Not fair.
Remove index 3: [2,1,6] -&gt; Even sum: 2 + 6 = 8. Odd sum: 1. Not fair.
There is 1 index that you can remove to make nums fair.


Example 2:

Input: nums = [1,1,1]
Output: 3
Explanation:&nbsp;You can remove any index and the remaining array is fair.


Example 3:

Input: nums = [1,2,3]
Output: 0
Explanation:&nbsp;You cannot make a fair array after removing any index.


&nbsp;
Constraints:


	1 &lt;= nums.length &lt;= 105
	1 &lt;= nums[i] &lt;= 104


class Solution:
	def waysToMakeFair(self, nums: List[int]) -> int:
		if len(nums) == 1:
			return 1

		if len(nums) == 2:
			return 0

		prefixEven = sum(nums[2::2])
		prefixOdd = sum(nums[1::2])
		result = 0

		if prefixEven == prefixOdd and len(set(nums)) == 1:
			result += 1

		for i in range(1,len(nums)):
			if i == 1:
				prefixOdd, prefixEven = prefixEven, prefixOdd 

			if i > 1:
				if i % 2 == 0:
					prefixEven -= nums[i-1]
					prefixEven += nums[i-2]

				else:
					prefixOdd -= nums[i-1]
					prefixOdd += nums[i-2]

			if prefixOdd == prefixEven:
				result += 1

		return result
class Solution {
    public int waysToMakeFair(int[] nums) {
        
        /*
        Idea - 
        
        have left (odd & even) & right (odd & even) odd & even sums separately
        
        as we move each element subtract & add appropriately
        */
        int count = 0;
        
        int evenLeft = 0;
        int oddLeft = 0;
        
        int evenRight = 0;
        int oddRight = 0;
            
        // calculate the right odd & even initially since we move from 0->n
        for(int i=0;i<nums.length;i++)
        {
            if(i%2 == 0)
            {
                evenRight+=nums[i];
            } else{
                oddRight+= nums[i];
            }
        }
        
        // move from 0 -> n
        for(int i=0;i<nums.length;i++)
        {
            
            // start from 1 since left at 0 index is 0 anyways & array bounds checked
            if(i>0)
            {
                // add previous element to left count
                if(i%2 == 0)
                {
                     oddLeft +=nums[i-1];
                } else{
                     evenLeft+=nums[i-1];
                }
            }
            
            // subtract current element value from right counts so we get right count excluding the current element
            if(i%2 == 0)
            {
                evenRight-=nums[i];
            } else{
                oddRight-=nums[i];
            }
            
            // if at any point we have below condition true increment count
            // notice here we are adding even & odd of opposite sides here since on excluding the current element the right counterpart sum switches
            // i.e if it was odd before it becomes even, else if it was even becomes odd
             if(evenLeft+oddRight == oddLeft+evenRight)
                {
                    count++;
                }
        }
        return count;
    }
}
class Solution {
public:
    int waysToMakeFair(vector<int>& nums) {
        //it looks a quite complicated problem but actually it is not
        //the main observation here is when a element is deleted the odd sum after the element becomes the evensum and vice versa
        //so we maintain two vectors left and right
        vector<int> left(2,0);
        vector<int> right(2,0);
        
        //left[0],right[0] stores the sum of even indices elements to the left and right side of the element respectively
        //left[1] right[1] stores the sum of odd indices elements to the left and right side of the element respectively
        
        int ans=0; //stores the result
        //first store the odd sum and even sum in right
        for(int i=0;i<nums.size();i++)
        {
            if(i%2)
            {
                //odd index 
                right[1]+=nums[i];
            }
            else{
                //even index 
                right[0]+=nums[i];
            }
        }
        
        //now traverse through every element in the array and try to remove the element  and check does it makes a fair array
        for(int i=0;i<nums.size();i++)
        {
            //try to remove the element
            int currOdd=right[1];
            int currEven=right[0];
            if(i%2)
            {
                //odd index , remove it from currOdd
                currOdd-=nums[i];
                right[1]-=nums[i]; //since it would be no longer to the right
            }
            else{
                //even index , remove it from currEven
                currEven-=nums[i];
                right[0]-=nums[i];
            }
            //now check whether the total oddSum and the evenSum in the array are equal ?
            //since we are deleting this element oddSum becomes evenSum and evenSum becomes oddSum
            //check leftOdd+rightOdd==rightEven+leftEven
            //left[0] is even sum to left of i 
            //left[1] is the odd sum to left of i
            if(left[0]+currOdd==left[1]+currEven)
                ans++;
            //since we traverse to right add this value to the left array
            (i%2) ? left[1]+=nums[i] : left[0]+=nums[i];
        }
        
        return ans;
    }
};
/**
 * @param {number[]} nums
 * @return {number}
 */
var waysToMakeFair = function(nums) {
    let oddSum = 0; 
    let evenSum = 0 ;
    let count = 0;
    
    for (let i = 0; i < nums.length; i++) {
        if (i % 2 === 0) {
            evenSum += nums[i];
        } else {
            oddSum += nums[i];
        }
    }
    
    
    for (let i = 0; i < nums.length; i++) {
        if (i % 2 === 0) {
            evenSum -= nums[i];
            if (evenSum === oddSum) {
                count++; 
            }
            oddSum += nums[i];
        } else {
            oddSum -= nums[i];
            if (evenSum === oddSum) {
                count++;
            }
            evenSum += nums[i]
        }
    }
    
    return count;
};
Ways to Make a Fair Array