[C++] Min and Max Heaps / Count Array
cpp\nclass Solution {\npublic:\n    string sortString(string s) {\n        string t;\n\t\tpriority_queue<char, vector<char>, greater<char>> pq1(s.begin(), s.end
```cpp\nclass Solution {\npublic:\n    string sortString(string s) {\n        string t;\n\t\tpriority_queue<char, vector<char>, greater<char>> pq1(s.begin(), s.end());\n        priority_queue<char> pq2;\n        \n        while (!pq1.empty() || !pq2.empty()) {\n            bool isFirst(true);\n            while (!pq1.empty()) {\n                if (isFirst) {\n                    t += pq1.top();\n                    isFirst = false;\n                } else if (t.back() < pq1.top()) t += pq1.top();\n                else pq2.push(pq1.top());\n                pq1.pop();\n            }\n            isFirst = true;\n            while (!pq2.empty()) {\n                if (isFirst) {\n                    t += pq2.top();\n                    isFirst = false;\n                } else if (t.back() > pq2.top()) t += pq2.top();\n                else pq1.push(pq2.top());\n                pq2.pop();\n            }\n        }\n        return t;\n    }\n};\n```\n\n```cpp\nclass Solution {\npublic:\n    string sortString(string s) {\n        int letters[26] = {};\n        string t;\n        \n        for (const char& c: s) letters[c - \'a\']++;\n            \n        while (true) {\n            for (int i = 0; i < 26; ++i)\n                if (letters[i]-- > 0)\n                    t += \'a\' + i;\n            for (int i = 25; i >= 0; --i)\n                if (letters[i]-- > 0)\n                    t += \'a\' + i;\n            if (s.length() == t.length()) break;\n        }\n        return t;\n    }\n};\n```
[]