<p>Given two integers n and k, return <em>an array of all the integers of length </em><code>n</code><em> where the difference between every two consecutive digits is </em><code>k</code>. You may return the answer in <strong>any order</strong>.</p>

<p>Note that the integers should not have leading zeros. Integers as <code>02</code> and <code>043</code> are not allowed.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> n = 3, k = 7
<strong>Output:</strong> [181,292,707,818,929]
<strong>Explanation:</strong> Note that 070 is not a valid number, because it has leading zeroes.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> n = 2, k = 1
<strong>Output:</strong> [10,12,21,23,32,34,43,45,54,56,65,67,76,78,87,89,98]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>2 &lt;= n &lt;= 9</code></li>
	<li><code>0 &lt;= k &lt;= 9</code></li>
</ul>

class Solution:
    def numsSameConsecDiff(self, n: int, k: int) -> List[int]:
        # init resulting data structure
        res=[]
        # loop over possible numbers
        # possible numbers are between 1 to 9
        for num in range(1,10):
            # we will pick num, since we've picked num we'll
            # reduce pos_left by 1(n-1)
            # we will pass num, n-1(pos_left), k and res to build_number
            self.build_number(num,n-1,k,res)
        # return res
        return res
    
    def build_number(self,num,pos_left,k:int,res:List[int]):
        # base case
        # if there are no positions left to fill
        if pos_left==0:
            # append the current num to res
            res.append(num)
            return res
        # find the last_digit of num
        last_digit=num%10
        # if last_digit+k<=9
        if last_digit+k<=9:
            # then add this(last_digit+k) to the number
            # reduce pos_left by 1 as we've picked another number
            self.build_number(num*10+(last_digit+k),pos_left-1,k,res)
        # if last_digit-k>=0 and k!=0, we're keeping case of k!=0 here because
        # when k is zero it will lead to duplicates as last_digit-k=last_digit+k 
        if last_digit-k>=0 and k!=0:
            # then add this(last_digit-k) to the number
            # reduce pos_left by 1 as we've picked another number
            self.build_number(num*10+(last_digit-k),pos_left-1,k,res)
16700