XOR of all subarray XORs | Set 2 | Returns XOR of all subarray xors ; if even number of terms are there , all numbers will appear even number of times . So result is 0. ; else initialize result by 0 as ( a xor 0 = a ) ; Driver Code
function getTotalXorOfSubarrayXors ( arr , N ) { if ( N % 2 == 0 ) return 0 ; let res = 0 ; for ( let i = 0 ; i < N ; i += 2 ) { res ^= arr [ i ] ; } return res ; } let arr = [ 3 , 5 , 2 , 4 , 6 ] ; let N = arr . length ; document . write ( getTotalXorOfSubarrayXors ( arr , N ) ) ;