Greatest number that can be formed from a pair in a given Array | Python3 implementation to find the greatest number from the given pairs of the array ; Function to find the greatest number formed from the pairs ; first append Y at the end of X ; then append X at the end of Y ; Now see which of the two formed numbers is greater than other ; Function to find pairs from array ; Iterate through all pairs ; Driver code
import sys ; NEW_LINE def getNumber ( a , b ) : NEW_LINE INDENT X = str ( a ) ; NEW_LINE Y = str ( b ) ; NEW_LINE XY = X + Y ; NEW_LINE YX = Y + X ; NEW_LINE if ( XY > YX ) : NEW_LINE INDENT return XY ; NEW_LINE DEDENT else : NEW_LINE INDENT return YX ; NEW_LINE DEDENT DEDENT def printMaxPair ( arr , n ) : NEW_LINE INDENT largest = - sys . maxsize - 1 ; NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT number = int ( getNumber ( arr [ i ] , arr [ j ] ) ) ; NEW_LINE largest = max ( largest , number ) ; NEW_LINE DEDENT DEDENT print ( largest ) ; NEW_LINE DEDENT a = [ 23 , 14 , 16 , 25 , 3 , 9 ] ; NEW_LINE n = len ( a ) ; NEW_LINE printMaxPair ( a , n ) ; NEW_LINE