<p>Given a string <code>s</code>, sort it in <strong>decreasing order</strong> based on the <strong>frequency</strong> of the characters. The <strong>frequency</strong> of a character is the number of times it appears in the string.</p>

<p>Return <em>the sorted string</em>. If there are multiple answers, return <em>any of them</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;tree&quot;
<strong>Output:</strong> &quot;eert&quot;
<strong>Explanation:</strong> &#39;e&#39; appears twice while &#39;r&#39; and &#39;t&#39; both appear once.
So &#39;e&#39; must appear before both &#39;r&#39; and &#39;t&#39;. Therefore &quot;eetr&quot; is also a valid answer.
</pre>

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

<pre>
<strong>Input:</strong> s = &quot;cccaaa&quot;
<strong>Output:</strong> &quot;aaaccc&quot;
<strong>Explanation:</strong> Both &#39;c&#39; and &#39;a&#39; appear three times, so both &quot;cccaaa&quot; and &quot;aaaccc&quot; are valid answers.
Note that &quot;cacaca&quot; is incorrect, as the same characters must be together.
</pre>

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

<pre>
<strong>Input:</strong> s = &quot;Aabb&quot;
<strong>Output:</strong> &quot;bbAa&quot;
<strong>Explanation:</strong> &quot;bbaA&quot; is also a valid answer, but &quot;Aabb&quot; is incorrect.
Note that &#39;A&#39; and &#39;a&#39; are treated as two different characters.
</pre>

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

<ul>
	<li><code>1 &lt;= s.length &lt;= 5 * 10<sup>5</sup></code></li>
	<li><code>s</code> consists of uppercase and lowercase English letters and digits.</li>
</ul>

class Solution {
private:
    // string create(vector<int> lower, vector<int> upper, vector<int> digits) {
    //     string str = "";
    //     int i = 25;
    //     int j = i;
    //     int k = 9;
    //     while(i >= 0 && j >= 0 && k >= 0) {
    //         if(lower[i] > upper[j] && lower[i] > digits[k]) {
    //             for(int l = 0; l < lower[i]; l++) {
    //                 char ch = 'a' + i;
    //                 str+=ch;
    //             }
    //             i--;
    //         }
    //         else if(upper[j] > lower[i] && upper[j] > digits[k]) {
    //             for(int l = 0; l < upper[j]; l++) {
    //                 char ch = 'A' + i;
    //                 str+=ch;
    //             }
    //             j--;
    //         }
    //         else {
    //             for(int l = 0; l < digits[k]; l++) {
    //                 char ch = '0' + i;
    //                 str+=ch;
    //             }
    //             k--;
    //         }
    //     }
    //     if (k < 0) {
    //     while(i >= 0 && j >= 0) {
    //          if(lower[i] > upper[j] && lower[i] > digits[k]) {
    //             for(int l = 0; l < lower[i]; l++) {
    //                 char ch = 'a' + i;
    //                 str+=ch;
    //             }
    //             i--;
    //         }
    //         else if(upper[j] > lower[i] && upper[j] > digits[k]) {
    //             for(int l = 0; l < upper[j]; l++) {
    //                 char ch = 'A' + i;
    //                 str+=ch;
    //             }
    //             j--;
    //         }
    //     }
    //     }
    //     else if(i < 0)


        
    // }
public:
    string frequencySort(string s) {
        vector<string> v(62);
        for(int i = 0; i < s.length(); i++) {
            char ch = s[i];
            if(ch >= 'a' && ch <= 'z') {
                v[ch - 'a']+=ch;
            }
            else if(ch >= 'A' && ch <= 'Z') {
                v[ch - 'A' + 26]+=ch;
            }
            else {
                v[ch - '0' + 52]+=ch;
            }
        }
        for(int i = 0; i < 61; i++) {
            int maxIndex = i;
            for(int j = i + 1; j < 62; j++) {
                if(v[maxIndex].length() < v[j].length()) {
                    maxIndex = j;
                }
            }
            swap(v[maxIndex], v[i]);
        }
        string str = "";
        for(int i = 0; i < 62; i++) {
            str+=v[i];
        }
        return str;        
        // for(int i = 0; i < s.length(); i++) {
        //     int ch = s[i];
        //     if(ch >= 65 && ch <= 90) {
        //         int index = ch - 'A';
        //         lower[index]++;
        //     }
        //     else if(ch >= 97 && ch <= 122) {
        //         int index = ch - 'a';
        //         upper[index]++;
        //     }
        //     else {
        //         int index = ch - '0';
        //         digits[index]++;
        //     }
        // }
        // sort(lower.begin(), lower.end());
        // sort(upper.begin(), upper.end());
        // sort(digits.begin(), digits.end());
        // string str = create(lower, upper, digits);
    }
};
10700