human
Stepping Numbers | Prints all stepping numbers reachable from num and in range [ n , m ].
If Stepping Number is in the range [ n , m ] then display.
If Stepping Number is 0 or greater than m , then return.
Get the last digit of the currently visited Stepping Number.
There can be 2 cases either digit to be appended is lastDigit + 1 or lastDigit - 1.
If lastDigit is 0 then only possible digit after 0 can be 1 for a Stepping Number.
If lastDigit is 9 then only possible digit after 9 can be 8 for a Stepping Number.
Method displays all the stepping numbers in range [ n , m ].
For every single digit Number ' i ' find all the Stepping Numbers starting with i.
Driver code.
Display Stepping Numbers in the range [ n , m ]"
How can the above be solved in Python?
assistant
#Here is code to stepping Numbers and the other steps required.
 def dfs ( n , m , stepNum ) :
	if ( stepNum <= m and stepNum >= n ) :
		print ( stepNum , end = " ▁ " )
	if ( stepNum == 0 or stepNum > m ) :
		return
	lastDigit = stepNum % 10
	stepNumA = stepNum * 10 + ( lastDigit - 1 )
	stepNumB = stepNum * 10 + ( lastDigit + 1 )
	if ( lastDigit == 0 ) :
		dfs ( n , m , stepNumB )
	elif ( lastDigit == 9 ) :
		dfs ( n , m , stepNumA )
	else :
		dfs ( n , m , stepNumA )
		dfs ( n , m , stepNumB )
def displaySteppingNumbers ( n , m ) :
	for i in range ( 10 ) :
		dfs ( n , m , i )
n , m = 0 , 21
displaySteppingNumbers ( n , m )