<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 originalDigits(string s) {
        vector<vector<int>> countV = formCounts();
        vector<int> v = formCountOfAString(s);
        vector<int> vFreq(10, 0);
        customOriginalDigits(v, countV, vFreq);
        return formStringFromFreq(vFreq);
    }

    string formStringFromFreq(vector<int> vFreq){
        string vs = "";
        for(int lv = 0; lv < (int)vFreq.size(); lv++){
            while(vFreq[lv]-- > 0){
                vs += to_string(lv);
            }
        }
        return vs;
    }

    void customOriginalDigits(vector<int>& v, vector<vector<int>>& countV, vector<int>& vFreq){
        for(int lv = 0; lv < 9; lv += 2){
            while(isDigitPresent(v, countV[lv])){
                removeDigit(v, countV[lv]);
                vFreq[lv] += 1;
            }
        }
        for(int lv = 1; lv < 10; lv += 2){
            while(isDigitPresent(v, countV[lv])){
                removeDigit(v, countV[lv]);
                vFreq[lv] += 1;
            }
        }
        
    }

    void removeDigit(vector<int>& v, vector<int>& cV){
        for(int lv = 0; lv < 26; lv++) v[lv] -= cV[lv];
    }

    bool isDigitPresent(vector<int>& v, vector<int>& cV){
        for(int lv = 0; lv < 26; lv++){
            if(cV[lv] > v[lv]) return false;
        }
        return true;
    }

    vector<vector<int>> formCounts(){
        vector<vector<int>> countV;
        vector<string> vS = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
        for(int lv = 0; lv < vS.size(); lv++){
            countV.push_back(formCountOfAString(vS[lv]));
        }
        return countV;
    }

    vector<int> formCountOfAString(string s){
        vector<int> cD(26, 0);
        for(int lv1 = 0; lv1 < s.size(); lv1++){
            cD[s[lv1]-'a'] += 1;
        }
        return cD;
    }
};
13300