Minimum XOR of OR and AND of any pair in the Array | C # program to for above approach ; Function to find the minimum value of XOR of AND and OR of any pair in the given array ; Sort the array ; Traverse the array arr [ ] ; Compare and Find the minimum XOR value of an array . ; Return the final answer ; Driver Code ; Given array arr [ ] ; Function Call
using System ; class GFG { static int maxAndXor ( int [ ] arr , int n ) { int ans = 9999999 ; Array . Sort ( arr ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) { ans = Math . Min ( ans , arr [ i ] ^ arr [ i + 1 ] ) ; } return ans ; } public static void Main ( ) { int [ ] arr = new int [ ] { 1 , 2 , 3 , 4 , 5 } ; int N = arr . Length ; Console . Write ( maxAndXor ( arr , N ) ) ; } }