JavaScript Solution O(n)


#1

module.exports = {
//param A : array of integers
//return an integer
solve : function(A){
let lteven=0;
let rteven=0;
let ltodd=0;
let rtodd=0;
let count=0;

for(let i=0;i<A.length;i++)

{
if(i%2===0)
{
rteven+=A[i];
}
else
{
rtodd+=A[i];
}
}

for(let i=0;i<A.length;i++)
{
if(i%2===0)
{
rteven-=A[i]

 }
 else
 {
     rtodd-=A[i];
 }
 if((lteven+rtodd)===(rteven + ltodd))
 {
     count++
 }
 if(i%2===0)
 {
     lteven+=A[i];
     
 }
 else
 {
     ltodd+=A[i];
 }

}

return count;

}

};