Make Array elements equal by replacing adjacent elements with their XOR | Function to check if it is possible to make all the array elements equal using the given operation ; Stores the XOR of all elements of array A [ ] ; Case 1 , check if the XOR of the array A [ ] is 0 ; Maintains the XOR till the current element ; Iterate over the array ; If the current XOR is equal to the total XOR increment the count and initialize current XOR as 0 ; Print Answer ; Driver Code ; Function Call
function possibleEqualArray ( A , N ) { var tot_XOR = 0 ; for ( var i = 0 ; i < N ; i ++ ) { tot_XOR ^= A [ i ] ; } if ( tot_XOR == 0 ) { document . write ( " " ) ; return ; } var cur_XOR = 0 ; var cnt = 0 ; for ( var i = 0 ; i < N ; i ++ ) { cur_XOR ^= A [ i ] ; if ( cur_XOR == tot_XOR ) { cnt ++ ; cur_XOR = 0 ; } } if ( cnt > 2 ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } var A = [ 0 , 2 , 2 ] ; var N = ( A . length ) ; possibleEqualArray ( A , N ) ;