Minimize difference after changing all odd elements to even | Function to minimize the difference between two elements of array ; Find all the element which are possible by multiplying 2 to odd numbers ; Sort the array ; Find the minimum difference Iterate and find which adjacent elements have the minimum difference ; Print the minimum difference ; Driver Code ; Given array ; Function Call
def minDiff ( a , n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT if ( a [ i ] % 2 == 1 ) : NEW_LINE INDENT a . append ( a [ i ] * 2 ) NEW_LINE DEDENT DEDENT a = sorted ( a ) NEW_LINE mindifference = a [ 1 ] - a [ 0 ] NEW_LINE for i in range ( 1 , len ( a ) ) : NEW_LINE INDENT mindifference = min ( mindifference , a [ i ] - a [ i - 1 ] ) NEW_LINE DEDENT print ( mindifference ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 3 , 8 , 13 , 30 , 50 ] NEW_LINE n = len ( arr ) NEW_LINE minDiff ( arr , n ) NEW_LINE DEDENT