<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>

#include <string>
#include <unordered_map>

using namespace std;

class Solution {
public:
    string originalDigits(string s) {
        // Hash map to store the frequency of each letter in the input string
        unordered_map<char, int> count;
        for (char c : s) {
            count[c]++;
        }

        // Hash map to store the count of each digit (0-9)
        unordered_map<int, int> digitCount;

        // Find digits based on unique characters
        digitCount[0] = count['z']; // 'z' is unique to "zero"
        digitCount[2] = count['w']; // 'w' is unique to "two"
        digitCount[4] = count['u']; // 'u' is unique to "four"
        digitCount[6] = count['x']; // 'x' is unique to "six"
        digitCount[8] = count['g']; // 'g' is unique to "eight"

        // Find remaining digits
        digitCount[3] = count['h'] - digitCount[8]; // 'h' is in "three" and "eight"
        digitCount[5] = count['f'] - digitCount[4]; // 'f' is in "five" and "four"
        digitCount[7] = count['s'] - digitCount[6]; // 's' is in "seven" and "six"
        digitCount[1] = count['o'] - digitCount[0] - digitCount[2] - digitCount[4]; // 'o' is in "one", "zero", "two", and "four"
        digitCount[9] = count['i'] - digitCount[5] - digitCount[6] - digitCount[8]; // 'i' is in "nine", "five", "six", and "eight"

        // Construct the result based on the digit counts
        string result;
        for (int i = 0; i < 10; ++i) {
            for(int j = 0; j < digitCount[i]; ++j){
                result += (char)('0' + i);
            }
        }

        return result;
    }
};

11700