human
Check if a number has digits in the given Order | Check if the digits follow the correct order.
to store the previous digit.
pointer to tell what type of sequence are we dealing with.
check if we have same digit as the previous digit.
checking the peak point of the number.
check if we have same digit as the previous digit.
check if the digit is greater than the previous one If true , then break from the loop as we are in descending order part.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to check if a number has digits in the given Order and the other steps required.
 def isCorrectOrder ( n ) :
	flag = True ;
	prev = - 1 ;
	type = - 1 ;
	while ( n != 0 ) :
		if ( type == - 1 ) :
			if ( prev == - 1 ) :
				prev = n % 10 ;
				n = int ( n / 10 ) ;
				continue ;
			if ( prev == n % 10 ) :
				flag = False ;
				break ;
			if ( prev > n % 10 ) :
				type = 1 ;
				prev = n % 10 ;
				n = int ( n / 10 ) ;
				continue ;
			prev = n % 10 ;
			n = int ( n / 10 ) ;
		else :
			if ( prev == n % 10 ) :
				flag = False ;
				break ;
			if ( prev < n % 10 ) :
				flag = False ;
				break ;
			prev = n % 10 ;
			n = int ( n / 10 ) ;
	return flag ;
n = 123454321 ;
if ( isCorrectOrder ( n ) ) :
	print ( " YES " ) ;
else :
	print ( " NO " ) ;