stores number of zeroes and ones at even positions
var one_even = 0 , zero_even = 0 ; for ( var i = 0 ; i < N ; i ++ ) { if ( i % 2 == 0 ) { if ( s . charAt ( i ) == ' ' ) one_even ++ ; else zero_even ++ ; } } if ( one > zero ) return num - one_even ; else return num - zero_even ; }