Find the maximum subarray XOR in a given array | A simple Javascript program to find max subarray XOR ; Initialize result ; Pick starting points of subarrays ; To store xor of current subarray ; Pick ending points of subarrays starting with i ; Driver code
function maxSubarrayXOR ( arr , n ) { let ans = Number . MIN_VALUE ; for ( let i = 0 ; i < n ; i ++ ) { let curr_xor = 0 ; for ( let j = i ; j < n ; j ++ ) { curr_xor = curr_xor ^ arr [ j ] ; ans = Math . max ( ans , curr_xor ) ; } } return ans ; } let arr = [ 8 , 1 , 2 , 12 ] ; let n = arr . length ; document . write ( " " + maxSubarrayXOR ( arr , n ) ) ;