Simple Solution Using C++
\n\n# Code\n\nclass Solution {\npublic:\n    string sortString(string s) {\n        set<char>st;\n        unordered_map<char,int>mp;\n        for(auto x:s){\n  
\n\n# Code\n```\nclass Solution {\npublic:\n    string sortString(string s) {\n        set<char>st;\n        unordered_map<char,int>mp;\n        for(auto x:s){\n            st.insert(x);\n            mp[x]++;\n        }\n        string res="",temp="";\n        for(auto x:st) temp+=x;\n        while(res.size()<s.size()){\n            for(int i=0;i<temp.size();i++){\n                if(mp[temp[i]]>0){\n                    res+=temp[i];\n                    mp[temp[i]]--;\n                }\n            }\n            for(int i=temp.size()-1;i>=0;i--){\n                if(mp[temp[i]]>0){\n                    res+=temp[i];\n                    mp[temp[i]]--;\n                }\n            }\n        }\n        return res;\n        \n    }\n};\n```
['C++']