<p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p>

<p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.</p>
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/15/1200px-telephone-keypad2svg.png" style="width: 300px; height: 243px;" />
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> digits = &quot;23&quot;
<strong>Output:</strong> [&quot;ad&quot;,&quot;ae&quot;,&quot;af&quot;,&quot;bd&quot;,&quot;be&quot;,&quot;bf&quot;,&quot;cd&quot;,&quot;ce&quot;,&quot;cf&quot;]
</pre>

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

<pre>
<strong>Input:</strong> digits = &quot;&quot;
<strong>Output:</strong> []
</pre>

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

<pre>
<strong>Input:</strong> digits = &quot;2&quot;
<strong>Output:</strong> [&quot;a&quot;,&quot;b&quot;,&quot;c&quot;]
</pre>

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

<ul>
	<li><code>0 &lt;= digits.length &lt;= 4</code></li>
	<li><code>digits[i]</code> is a digit in the range <code>[&#39;2&#39;, &#39;9&#39;]</code>.</li>
</ul>

class Solution {
    int n, m;
    unordered_map<char, string> M;
    unordered_map<char, string> vis;
public:
    void backTrack(int idx, string s, string d, vector<string>& res) {
        if(s.size() == n) {
            res.push_back(s);
            return;
        }

        if(idx == n) {
            return;
        }

        // for(int i = 0; i < n; i++) {
            char c = d[idx];
            // if(vis[c].back() == '1')
            //     continue;

            // vis[c].back() = '1';

            for(int j = 0; j < M[c].size(); j++) {
                // if(vis[c][j] == '0') {
                    s += M[c][j];
                    // vis[c][j] = '1';
                    backTrack(idx+1, s, d, res);

                    // vis[c][j] = '0';
                    s.pop_back();
                // }
            }
            // vis[c].back() = '0';
        // }
    }

    vector<string> letterCombinations(string digits) {
        if(digits.size() == 0) {
            return {};
        }

        n = digits.size();
        vector<string> res;
        char tmp = 'a';
        for(int i = 2; i < 10; i++) {
            string s = "";
            int len = 3;
            if(i == 7 || i == 9) {
                len = 4;
            } 

            for(int j = 0; j < len; j++) {
                s += tmp + j;
            }

            char key = '0' + i;
            M[key] = s;
            tmp = s.back() + 1;
        }
        
        for(int i = 0; i < n; i++) {
            string s = M[digits[i]];
            if(s.size() == 3) {
                vis[digits[i]] = "0000";     //last char is selected state of digits[i]
            } 
            else
            {
                vis[digits[i]] = "00000";
            }
        }

        // for(auto it = M.begin(); it != M.end(); ++it) {
        //     cout << it->first << "-" << it->second << endl;
        // }

        backTrack(0, "", digits, res);
        return res;
    }
};
8800