text: Maximum value of XOR among all triplets of an array | C ++ implementation of the approach ; function to count maximum XOR value for a triplet ; set is used to avoid repetitions ; store all possible unique XOR value of pairs ; store maximum value ; Driver code
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; void Maximum_xor_Triplet ( int n , int a [ ] ) { set < int > s ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { s . insert ( a [ i ] ^ a [ j ] ) ; } } int ans = 0 ; for ( auto i : s ) { for ( int j = 0 ; j < n ; j ++ ) { ans = max ( ans , i ^ a [ j ] ) ; } } cout << ans << " STRNEWLINE " ; } int main ( ) { int a [ ] = { 1 , 3 , 8 , 15 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; Maximum_xor_Triplet ( n , a ) ; return 0 ; }