human
Print all n | n , sum -- > value of inputs out -- > output array index -- > index of next digit to be filled in output array.
Base case.
If number becomes N - digit.
if sum of its digits is equal to given sum , print it.
Traverse through every digit . Note that here we ' re ▁ considering ▁ leading ▁ ▁ 0' s as digits.
append current digit to number.
recurse for next digit with reduced sum.
This is mainly a wrapper over findNDigitNumsUtil . It explicitly handles leading digit.
output array to store N - digit numbers.
fill 1 st position by every digit from 1 to 9 and calls findNDigitNumsUtil ( ) for remaining positions.
Driver Code"
How can the above be solved in Python?
 Give me a code to print all n and the other steps required?
assistant
#Here is code to print all n and the other steps required.
 def findNDigitNumsUtil ( n , sum , out , index ) :
	if ( index > n or sum < 0 ) :
		return
	f = " "
	if ( index == n ) :
		if ( sum == 0 ) :
			out [ index ] = " \0"
			for i in out :
				f = f + i
			print ( f , end = " ▁ " )
		return
	for i in range ( 10 ) :
		out [ index ] = chr ( i + ord ( '0' ) )
		findNDigitNumsUtil ( n , sum - i , out , index + 1 )
def findNDigitNums ( n , sum ) :
	out = [ False ] * ( n + 1 )
	for i in range ( 1 , 10 ) :
		out [ 0 ] = chr ( i + ord ( '0' ) )
		findNDigitNumsUtil ( n , sum - i , out , 1 )
if __name__ == " _ _ main _ _ " :
	n = 2
	sum = 3
	findNDigitNums ( n , sum )