Find smallest number formed by inverting digits of given number N | Function to invert the digits of integer N to form minimum possible number ; Initialize the array ; Iterate till the number N exists ; Last digit of the number N ; Checking if the digit is smaller than 9 - digit ; Store the smaller digit in the array ; Reduce the number each time ; Check if the digit starts with 0 or not ; Print the answer ; Driver Code ; Given Number ; Function Call
def number ( num ) : NEW_LINE INDENT a = [ 0 ] * 20 NEW_LINE r , i , j = 0 , 0 , 0 NEW_LINE while ( num > 0 ) : NEW_LINE INDENT r = num % 10 NEW_LINE if ( 9 - r > r ) : NEW_LINE INDENT a [ i ] = r NEW_LINE DEDENT else : NEW_LINE INDENT a [ i ] = 9 - r NEW_LINE DEDENT i += 1 NEW_LINE num = num // 10 NEW_LINE DEDENT if ( a [ i - 1 ] == 0 ) : NEW_LINE INDENT print ( 9 , end = " " ) NEW_LINE i -= 1 NEW_LINE DEDENT for j in range ( i - 1 , - 1 , - 1 ) : NEW_LINE INDENT print ( a [ j ] , end = " " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT num = 4545 NEW_LINE number ( num ) NEW_LINE DEDENT