Largest number smaller than or equal to n and digits in non | Prints the largest number smaller than s and digits in non - decreasing order . ; array to store digits of number ; conversion of characters of string int number ; variable holds the value of index after which all digits are set 9 ; Checking the condition if the digit is less than its left digit ; If first digit is 0 no need to print it ; Driver Code
def nondecdigits ( s ) : NEW_LINE INDENT m = len ( s ) ; NEW_LINE a = [ 0 ] * m ; NEW_LINE for i in range ( m ) : NEW_LINE INDENT a [ i ] = ord ( s [ i ] ) - ord ( '0' ) ; NEW_LINE DEDENT level = m - 1 ; NEW_LINE for i in range ( m - 1 , 0 , - 1 ) : NEW_LINE INDENT if ( a [ i ] < a [ i - 1 ] ) : NEW_LINE INDENT a [ i - 1 ] -= 1 ; NEW_LINE level = i - 1 ; NEW_LINE DEDENT DEDENT if ( a [ 0 ] != 0 ) : NEW_LINE INDENT for i in range ( level + 1 ) : NEW_LINE INDENT print ( a [ i ] , end = " " ) ; NEW_LINE DEDENT for i in range ( level + 1 , m ) : NEW_LINE INDENT print ( "9" , end = " " ) ; NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT for i in range ( 1 , level ) : NEW_LINE INDENT print ( a [ i ] , end = " " ) ; NEW_LINE DEDENT for i in range ( level + 1 , m ) : NEW_LINE INDENT print ( "9" , end = " " ) ; NEW_LINE DEDENT DEDENT DEDENT n = "200" ; NEW_LINE nondecdigits ( n ) ; NEW_LINE