human
Nth positive number whose absolute difference of adjacent digits is at most 1 | Return Nth number with absolute difference between all adjacent digits at most 1..
To store all such numbers.
Enqueue all integers from 1 to 9 in increasing order ..
Perform the operation N times so that we can get all such N numbers ..
Store the front element of queue , in array and pop it from queue ..
If the last digit of dequeued integer is not 0 , then enqueue the next such number ..
Enqueue the next such number.
If the last digit of dequeued integer is not 9 , then enqueue the next such number ..
Driver Code"
How can the above be solved in Python?
 ... Can you provide a code to nth positive number whose absolute difference of adjacent digits is at most 1 and the other steps required?
assistant
#Here is code to nth positive number whose absolute difference of adjacent digits is at most 1 and the other steps required.
 def findNthNumber ( N ) :
	arr = [ 0 for i in range ( N + 1 ) ]
	q = [ ]
	for i in range ( 1 , 10 , 1 ) :
		q . append ( i )
	for i in range ( 1 , N + 1 , 1 ) :
		arr [ i ] = q [ 0 ]
		q . remove ( q [ 0 ] )
		if ( arr [ i ] % 10 != 0 ) :
			q . append ( arr [ i ] * 10 + arr [ i ] % 10 - 1 )
		q . append ( arr [ i ] * 10 + arr [ i ] % 10 )
		if ( arr [ i ] % 10 != 9 ) :
			q . append ( arr [ i ] * 10 + arr [ i ] % 10 + 1 )
	print ( arr [ N ] )
if __name__ == ' _ _ main _ _ ' :
	N = 21
	findNthNumber ( N )