<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 {
public:
    vector<int> numsSameConsecDiff(int n, int k) {
        vector<int> ans;
        // if(k==1)
        // for (long long i = pow(10, n - 1); i < pow(10, n); i++) {
        //     int x = i;
        //     int d = x % 10;
        //     x /= 10;
        //     bool ch = true;
        //     while (x > 0) {
        //         int dig = x % 10;
        //         if (abs(d - dig) != k) {
        //             ch = false;
        //             break;
        //         }
        //         x/=10;
        //         d=dig;
        //     }
        //     if(ch)
        //     ans.push_back(i);
        // }
        queue<string> q;
        // q.push("0");
        q.push("1");
        q.push("2");
        q.push("3");
        q.push("4");
        q.push("5");
        q.push("6");
        q.push("7");
        q.push("8");
        q.push("9");
        while (!q.empty()) {
            string s = q.front();
            q.pop();
           
            if (s.size() == n) {
                ans.push_back(stoi(s));
                continue;
            }
             int last = stoi(s)%10;
             string str=s;
             if(k+last<=9)
             {
               q.push(s + to_string(last + k));

             }
             if(k!=0 and last-k>=0){
               q.push(s + to_string(last - k)); 
             }
            //  q.push(str);
            // for (int i = 0; i <= 9; i++) {
            //     if (abs(last - i) == k) {
            //         string str=s;
            //         str.push_back(i + '0');
            //         q.push(str);
            //     }
            // }
        }
        return ans;
    }
};
12900