Find the minimum value of the given expression over all pairs of the array | C # program to find the minimum value of the given expression over all pairs of the array ; Function to find the minimum value of the expression ; The expression simplifies to finding the minimum xor value pair Sort given array ; Calculate min xor of consecutive pairs ; Driver Code
using System ; class GFG { static int MinimumValue ( int [ ] arr , int n ) { Array . Sort ( arr ) ; int minXor = Int32 . MaxValue ; int val = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { val = arr [ i ] ^ arr [ i + 1 ] ; minXor = Math . Min ( minXor , val ) ; } return minXor ; } public static void Main ( ) { int N = 6 ; int [ ] A = new int [ ] { 12 , 3 , 14 , 5 , 9 , 8 } ; Console . Write ( MinimumValue ( A , N ) ) ; } }