text: Find a number such that maximum in array is minimum possible after XOR | C # program that find the minimum possible maximum ; Recursive function that find the minimum value after exclusive - OR ; Condition if ref size is zero or bit is negative then return 0 ; Condition if current bit is off then push current value in curr_off vector ; Condition if current bit is on then push current value in curr_on vector ; Condition if curr_off is empty then call recursive function on curr_on vector ; Condition if curr_on is empty then call recursive function on curr_off vector ; Return the minimum of curr_off and curr_on and add power of 2 of current bit ; Function that print the minimum value after exclusive - OR ; Pushing values in vector ; Printing answer ; Driver Code
code: using System ; using System . Collections . Generic ; class GFG { static int RecursiveFunction ( List < int > re , int bit ) { if ( re . Count == 0 bit < 0 ) return 0 ; List < int > curr_on = new List < int > ( ) ; List < int > curr_off = new List < int > ( ) ; for ( int i = 0 ; i < re . Count ; i ++ ) { if ( ( ( re [ i ] >> bit ) & 1 ) == 0 ) curr_off . Add ( re [ i ] ) ; else curr_on . Add ( re [ i ] ) ; } if ( curr_off . Count == 0 ) return RecursiveFunction ( curr_on , bit - 1 ) ; if ( curr_on . Count == 0 ) return RecursiveFunction ( curr_off , bit - 1 ) ; return Math . Min ( RecursiveFunction ( curr_off , bit - 1 ) , RecursiveFunction ( curr_on , bit - 1 ) ) + ( 1 << bit ) ; } static void PrintMinimum ( int [ ] a , int n ) { List < int > v = new List < int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) v . Add ( a [ i ] ) ; Console . WriteLine ( RecursiveFunction ( v , 30 ) ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 2 , 1 } ; int size = arr . Length ; PrintMinimum ( arr , size ) ; } }