<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>

# find all pairs
# digits = 0,9

# pairs = set()



class Solution:
    def numsSameConsecDiff(self, n: int, k: int) -> List[int]:
        
        def dfs(ans):
            if len(ans) == n:
                return [ans]

            a = int(ans[-1]) + k
            b = int(ans[-1]) - k 
            res_a = None
            res_b = None

            if a <= 9:
                res_a = dfs(ans+str(a))

            if b >= 0:
                res_b = dfs(ans+str(b))

            if res_a and res_b:
                return res_a + res_b
            if res_a:
                return res_a
            return res_b
        

        res = set()

        for i in range(1,10):
            dfs_res = dfs(str(i))

            if dfs_res:
                for a in dfs_res:
                    res.add(int(a))
        
        return list(res)
        
        

        # f(ans) =[ans]
        # f(ans) = if ans[-1]+k <9 then f("ans"+"ans[-1]+k") + if ans[-1]-k >= 0 then f("ans" + "ans[-1]-k") 
         

        
16500