Find the maximum subarray XOR in a given array | A simple C ++ program to find max subarray XOR ; Initialize result ; Pick starting points of subarrays ; Pick ending points of subarrays starting with i ; Driver program to test above functions
#include <bits/stdc++.h> NEW_LINE using namespace std ; int maxSubarrayXOR ( int arr [ ] , int n ) { int ans = INT_MIN ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { curr_xor = curr_xor ^ arr [ j ] ; ans = max ( ans , curr_xor ) ; } } return ans ; } int main ( ) { int arr [ ] = { 8 , 1 , 2 , 12 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Max ▁ subarray ▁ XOR ▁ is ▁ " << maxSubarrayXOR ( arr , n ) ; return 0 ; }