C++ Solution
\nclass Solution {\npublic:\n    string sortString(string s) {\n        std::map<char,int> alpha;\n        string ans="";\n        \n        for(const auto &i:s
```\nclass Solution {\npublic:\n    string sortString(string s) {\n        std::map<char,int> alpha;\n        string ans="";\n        \n        for(const auto &i:s)\n        {\n            if(alpha.find(i)==alpha.end())\n            {\n                alpha.insert({i,1});\n            }\n            else\n            {\n                alpha[i]++;\n            }\n        }\n        \n        int len=s.size();\n        \n        while(len)\n        {\n            for(auto &[key,val] : alpha)\n            {\n                if(val)\n                {\n                    ans+=key;\n                    val--;\n                    len--;\n                }\n            }\n            for(auto x=alpha.rbegin();x!=alpha.rend();x++)\n            {\n                if(x->second)\n                {\n                    ans+=x->first;\n                    x->second--;\n                    len--;\n                }\n            }\n        }\n        return ans;\n    }\n};\n```
[]