stores number of ones at odd and even position respectively
var one_odd = 0 , one_even = 0 ; for ( var i = 0 ; i < N ; i ++ ) { if ( s . charAt ( i ) == ' ' ) { if ( i % 2 == 1 ) one_odd ++ ; else one_even ++ ; } } return Math . min ( N / 2 - one_odd , N / 2 - one_even ) ; } }