Find maximum number that can be formed using digits of a given number | Function to print maximum number ; Hashed array to store count of digits ; Converting given number to string ; Updating the count array ; Result stores final number ; traversing the count array to calculate the maximum number ; return the result ; Driver code
def printMaximum ( inum ) : NEW_LINE INDENT count = [ 0 for x in range ( 10 ) ] NEW_LINE string = str ( num ) NEW_LINE for i in range ( len ( string ) ) : NEW_LINE INDENT count [ int ( string [ i ] ) ] = count [ int ( string [ i ] ) ] + 1 NEW_LINE DEDENT result = 0 NEW_LINE multiplier = 1 NEW_LINE for i in range ( 10 ) : NEW_LINE INDENT while count [ i ] > 0 : NEW_LINE INDENT result = result + ( i * multiplier ) NEW_LINE count [ i ] = count [ i ] - 1 NEW_LINE multiplier = multiplier * 10 NEW_LINE DEDENT DEDENT return result NEW_LINE DEDENT num = 38293367 NEW_LINE print printMaximum ( num ) NEW_LINE