Maximum possible number with the given operation | Function to return the maximum possible integer that can be obtained from the given integer after performing the given operations ; For every digit ; Digits greater than or equal to 5 need not to be changed as changing them will lead to a smaller number ; The resulting integer cannot have leading zero ; Driver code
def maxInt ( string ) : NEW_LINE INDENT string2 = " " NEW_LINE for i in range ( 0 , len ( string ) ) : NEW_LINE INDENT if ( string [ i ] < '5' ) : NEW_LINE INDENT string2 += str ( ( ord ( '9' ) - ord ( string [ i ] ) ) ) NEW_LINE DEDENT else : NEW_LINE INDENT string2 += str ( string [ i ] ) NEW_LINE DEDENT DEDENT if ( string2 [ 0 ] == '0' ) : NEW_LINE INDENT string2 [ 0 ] = '9' NEW_LINE DEDENT return string2 NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT string = "42" NEW_LINE print ( maxInt ( string ) ) NEW_LINE DEDENT