<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) {
        // 1. Declare state variables
        int length = s.length();
        std::vector<int> charCount(256, 0);
        
        // 2. Update count of characters
        for (int i = 0; i < length; i++) {
            charCount[s[i]]++;
        }
        
        // 3. Update the string
        std::string ans {};
        int val { 0 };
        
        // 3.0.
        val = charCount['z'];
        if (val) {
            ans.append(val, '0');
            charCount['z'] -= val;
            charCount['e'] -= val;
            charCount['r'] -= val;
            charCount['o'] -= val;
        }
        
        // 3.2.
        val = charCount['w'];
        if (val) {
            ans.append(val, '2');
            charCount['t'] -= val;
            charCount['w'] -= val;
            charCount['o'] -= val;
        }

        // 3.4.
        val = charCount['u'];
        if (val) {
            ans.append(val, '4');
            charCount['f'] -= val;
            charCount['o'] -= val;
            charCount['u'] -= val;
            charCount['r'] -= val;
        }

        // 3.6.
        val = charCount['x'];
        if (val) {
            ans.append(val, '6');
            charCount['s'] -= val;
            charCount['i'] -= val;
            charCount['x'] -= val;
        }

        // 3.8.
        val = charCount['g'];
        if (val) {
            ans.append(val, '8');
            charCount['e'] -= val;
            charCount['i'] -= val;
            charCount['g'] -= val;
            charCount['h'] -= val;
            charCount['t'] -= val;
        }
        
        // 3.3.
        val = charCount['h'];
        if (val) {
            ans.append(val, '3');
            charCount['t'] -= val;
            charCount['h'] -= val;
            charCount['r'] -= val;
            charCount['e'] -= val * 2;
        }

        // 3.1.
        val = std::min(std::min(charCount['o'], charCount['n']), charCount['e']);
        if (val) {
            ans.append(val, '1');
            charCount['o'] -= val;
            charCount['n'] -= val;
            charCount['e'] -= val;
        }

        // 3.5.
        val = std::min(std::min(std::min(charCount['f'], charCount['i']), charCount['v']), charCount['e']);
        if (val) {
            ans.append(val, '5');
            charCount['f'] -= val;
            charCount['i'] -= val;
            charCount['v'] -= val;
            charCount['e'] -= val;
        }

        // 3.7.
        val = std::min(std::min(std::min(charCount['s'], charCount['v']), charCount['n']), charCount['e'] / 2);
        if (val) {
            ans.append(val, '7');
            charCount['s'] -= val;
            charCount['v'] -= val;
            charCount['n'] -= val;
            charCount['e'] -= val * 2;
        }

        // 3.9.
        val = std::min(std::min(charCount['i'], charCount['e']), charCount['n'] / 2);
        if (val) {
            ans.append(val, '9');
            charCount['i'] -= val;
            charCount['e'] -= val;
            charCount['n'] -= val * 2;
        }
        
        std::sort(ans.begin(), ans.end());

        return ans;
    }
};
10600