human
Find the closest and smaller tidy number | Python 3 program to find closest tidy number smaller than the given number.
check whether string violates tidy property.
if string violates tidy property , then decrease the value stored at that index by 1 and replace all the value stored right to that index by 9.
Driver code.
num will store closest tidy number"
How can the above be solved in Python?
assistant
#Here is code to find the closest and smaller tidy number and the other steps required.
 def tidyNum ( str , len ) :
	for i in range ( len - 2 , - 1 , - 1 ) :
		if ( str [ i ] > str [ i + 1 ] ) :
			str [ i ] -= 1
			for j in range ( i + 1 , len ) :
				str [ j ] = 9
	return str
str = [ 1 , 1 , 3 , 3 , 3 , 4 , 4 , 5 , 5 , 3 , 8 ]
len = len ( str )
num = tidyNum ( str , len )
for i in range ( 0 , len ) :
	print ( str [ i ] , end = " " )