human
Generate all N digit numbers having absolute difference as K between adjacent digits | Function that recursively finds the possible numbers and append into ans.
Base Case.
Check the sum of last digit and k less than or equal to 9 or not.
If k == 0 , then subtraction and addition does not make any difference Hence , subtraction is skipped.
Function to call checkUntil function for every integer from 1 to 9.
check_util function recursively store all numbers starting from i.
Function to print the all numbers which satisfy the conditions.
Driver Code.
Given N and K.
To store the result.
Function call.
Print resultant numbers"
Solution in Python:
 What is a code to generate all N digit numbers having absolute difference as K between adjacent digits and the other steps required?
assistant
#Here is code to generate all N digit numbers having absolute difference as K between adjacent digits and the other steps required.
 def checkUntil ( num , K , N , ans ) :
	if ( N == 1 ) :
		ans . append ( num )
		return
	if ( ( num % 10 + K ) <= 9 ) :
		checkUntil ( 10 * num + ( num % 10 + K ) , K , N - 1 , ans )
	if ( K ) :
		if ( ( num % 10 - K ) >= 0 ) :
			checkUntil ( 10 * num + num % 10 - K , K , N - 1 , ans )
def check ( K , N , ans ) :
	for i in range ( 1 , 10 ) :
		checkUntil ( i , K , N , ans )
def print_list ( ans ) :
	for i in range ( len ( ans ) ) :
		print ( ans [ i ] , end = " , ▁ " )
if __name__ == " _ _ main _ _ " :
	N = 4
	K = 8 ;
	ans = [ ]
	check ( K , N , ans )
	print_list ( ans )