text: Remove one element to get maximum XOR | C ++ implementation of the approach ; Function to return the maximized XOR after removing an element from the array ; Find XOR of the complete array ; To store the final answer ; Iterating through the array to find the final answer ; Return the final answer ; Driver code
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; int maxXOR ( int * arr , int n ) { int xorArr = 0 ; for ( int i = 0 ; i < n ; i ++ ) xorArr ^= arr [ i ] ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) ans = max ( ans , ( xorArr ^ arr [ i ] ) ) ; return ans ; } int main ( ) { int arr [ ] = { 1 , 1 , 3 } ; int n = sizeof ( arr ) / sizeof ( int ) ; cout << maxXOR ( arr , n ) ; return 0 ; }