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
using System ; using System . Collections . Generic ; class GFG { static void Maximum_xor_Triplet ( int n , int [ ] a ) { HashSet < int > s = new HashSet < int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { s . Add ( a [ i ] ^ a [ j ] ) ; } } int ans = 0 ; foreach ( int i in s ) { for ( int j = 0 ; j < n ; j ++ ) { ans = Math . Max ( ans , i ^ a [ j ] ) ; } } Console . WriteLine ( ans ) ; } public static void Main ( String [ ] args ) { int [ ] a = { 1 , 3 , 8 , 15 } ; int n = a . Length ; Maximum_xor_Triplet ( n , a ) ; } }