Binary array after M range toggle operations | function for toggle ; function for final processing of array ; function for printing result ; driver program ; function call for toggle ; process array ; print result
function command ( arr , a , b ) { arr [ a ] ^= 1 ; arr [ b + 1 ] ^= 1 ; } function process ( arr , n ) { for ( var k = 1 ; k <= n ; k ++ ) arr [ k ] ^= arr [ k - 1 ] ; } function result ( arr , n ) { for ( var k = 1 ; k <= n ; k ++ ) document . write ( arr [ k ] + " " ) ; } var n = 5 , m = 3 ; var arr = Array ( n + 2 ) . fill ( 0 ) ; command ( arr , 1 , 5 ) ; command ( arr , 2 , 5 ) ; command ( arr , 3 , 5 ) ; process ( arr , n ) ; result ( arr , n ) ;