XOR of all subarray XORs | Set 1 | Returns XOR of all subarray xors ; initialize result by 0 as ( a xor 0 = a ) ; select the starting element ; select the eNding element ; Do XOR of elements in current subarray ; Driver Code
function getTotalXorOfSubarrayXors ( arr , N ) { let res = 0 ; for ( let i = 0 ; i < N ; i ++ ) for ( let j = i ; j < N ; j ++ ) for ( let k = i ; k <= j ; k ++ ) res = res ^ arr [ k ] ; return res ; } let arr = [ 3 , 5 , 2 , 4 , 6 ] ; let N = arr . length ; document . write ( getTotalXorOfSubarrayXors ( arr , N ) ) ;