<p>Given a string <code>s</code> containing an out-of-order English representation of digits <code>0-9</code>, return <em>the digits in <strong>ascending</strong> order</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> s = "owoztneoer"
<strong>Output:</strong> "012"
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> s = "fviefuro"
<strong>Output:</strong> "45"
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
	<li><code>s[i]</code> is one of the characters <code>[&quot;e&quot;,&quot;g&quot;,&quot;f&quot;,&quot;i&quot;,&quot;h&quot;,&quot;o&quot;,&quot;n&quot;,&quot;s&quot;,&quot;r&quot;,&quot;u&quot;,&quot;t&quot;,&quot;w&quot;,&quot;v&quot;,&quot;x&quot;,&quot;z&quot;]</code>.</li>
	<li><code>s</code> is <strong>guaranteed</strong> to be valid.</li>
</ul>

class Solution {
public:
    /*
    string getDigits(string d, char digit, unordered_map<char, int>& m) {
        string res;
        while(1) {
            for(auto& c: d) {
                if(m[c] == 0) {
                    return res;
                }
            }
            for(auto& c: d) {
                m[c]--;
            }
            res.push_back(digit);
        }
        return res;
    }
    
    string originalDigits(string s) {
        unordered_map<char, int> m;
        int cnt = 0;
        for(auto& c: s) {
            m[c]++;
            cnt++;
        }
        string res;
        res = res + getDigits("zero", '0', m);
        res = res + getDigits("one", '1', m);
        res = res + getDigits("two", '2', m);
        res = res + getDigits("three", '3', m);
        res = res + getDigits("four", '4', m);
        res = res + getDigits("five", '5', m);
        res = res + getDigits("six", '6', m);
        res = res + getDigits("seven", '7', m);
        res = res + getDigits("eight", '8', m);
        res = res + getDigits("nine", '9', m);
        return res;
    }
    */
    vector<string> v = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    string ans;
    bool helper(unordered_map<char, int>& m, int cnt, string& res, int idx) {
        if(ans.size() != 0) {
            return true;
        }
        if(idx == v.size()) {
            if(cnt == 0) {
                ans = res;
                return true;
            }
            return false;
        }
        bool r;
        r = helper(m, cnt, res, idx+1);
        if(r) {
            return r;
        }
        
        int found = 1;
        cout << res << endl;
        for(auto c: v[idx]) {
            if(m[c] == 0) {
                found = 0;
                break;
            }
        } 
        
        if(found == 1) {
            for(auto c: v[idx]) {
                m[c]--;
                cnt--;
            }
            res = res + to_string(idx);
        }
        r = helper(m, cnt, res, idx);
        if(r) {
            return r;
        } else {
            if(found == 1) {
                res.pop_back();
                for(auto c: v[idx]) {
                    m[c]++;
                }
            }
            return false;
        }
    }
    string originalDigits(string s) {
          unordered_map<char, int> m;
        for(char c : s) m[c]++;

        string ans;
        vector<pair<pair<char, char>, string>> v = {{{'z', '0'}, "zero"}, {{'w', '2'}, "two"}, {{'u', '4'}, "four"}, 
                                                    {{'x', '6'}, "six"}, {{'g', '8'}, "eight"}, {{'o', '1'}, "one"}, 
                                                    {{'t', '3'}, "three"}, {{'f', '5'}, "five"}, {{'s', '7'}, "seven"}, 
                                                    {{'i', '9'}, "nine"}};
        for(auto p : v) {
            int n = m[p.first.first];
            for(int i=0; i<n; i++) ans += p.first.second;
            for(char c : p.second) m[c] -= n;
        }
        sort(ans.begin(), ans.end());
        return ans;
    }
};
11800