Maximum value of XOR among all triplets of an array | 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
function Maximum_xor_Triplet ( n , a ) { let s = new Set ( ) ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i ; j < n ; j ++ ) { s . add ( a [ i ] ^ a [ j ] ) ; } } let ans = 0 ; for ( let i of s . values ( ) ) { for ( let j = 0 ; j < n ; j ++ ) { ans = Math . max ( ans , i ^ a [ j ] ) ; } } document . write ( ans , " " ) ; } let a = [ 1 , 3 , 8 , 15 ] ; let n = a . length ; Maximum_xor_Triplet ( n , a ) ;