Find the minimum value of the given expression over all pairs of the array | Python3 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
import sys NEW_LINE def MinimumValue ( arr , n ) : NEW_LINE INDENT arr . sort ( ) ; NEW_LINE minXor = sys . maxsize ; NEW_LINE val = 0 ; NEW_LINE for i in range ( 0 , n - 1 ) : NEW_LINE INDENT val = arr [ i ] ^ arr [ i + 1 ] ; NEW_LINE minXor = min ( minXor , val ) ; NEW_LINE DEDENT return minXor ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 6 ; NEW_LINE A = [ 12 , 3 , 14 , 5 , 9 , 8 ] ; NEW_LINE print ( MinimumValue ( A , N ) ) ; NEW_LINE DEDENT