O(n) with O(1) memory


#1

int count = 0;
int odd = 0;
int even = 0;
for (int i = 0; i< A.length; i ++){
if(i%2 == 0){
even+=A[i];
} else {
odd +=A[i];
}
}
for (int i = A.length - 1; i>=0;i–){
boolean isEven = i%2 ==0;
if(isEven) even-=A[i];
else odd-=A[i];
if(odd ==even) count ++;
if(isEven) odd +=A[i];
else even +=A[i];
}
return count;


#2

The even and odd positions would change after you remove the element and you’ll have to compute the odd and even sum. So, how does this work?