Minimize K whose XOR with given array elements leaves array unchanged | Function to find the minimum value of K in given range ; Declare a set ; Initialize count variable ; Iterate in range [ 1 , 1024 ] ; counter set as 0 ; Iterating through the Set ; Check if the XOR calculated is present in the Set ; If the value of Bitwise XOR inside the given set then increment count ; Check if the value of count is equal to the size of set ; Return minimum value of K ; If no such K is found ; Given array ; Function Call
def min_value ( arr , N ) : NEW_LINE INDENT x , X , K = 0 , 0 , 0 NEW_LINE S = set ( ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT S . add ( arr [ i ] ) NEW_LINE DEDENT count = 0 NEW_LINE for i in range ( 1 , 1024 ) : NEW_LINE INDENT count = 0 NEW_LINE for it in S : NEW_LINE INDENT X = ( ( i it ) - ( i & it ) ) NEW_LINE if X in S : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT if ( count == len ( S ) ) : NEW_LINE INDENT K = i NEW_LINE return K NEW_LINE DEDENT DEDENT return - 1 NEW_LINE DEDENT arr = [ 1 , 0 , 3 , 3 , 0 , 2 ] NEW_LINE N = len ( arr ) NEW_LINE print ( min_value ( arr , N ) ) NEW_LINE