Simple to understand C++ code with slight explaination | 0 ms 100% faster code | O(26*n)
Hint : Just store the frequency of each character in frequency array which will be in sorted order starting from a-z ,traverse 2 times one for increasing part a
Hint : Just store the frequency of each character in frequency array which will be in sorted order starting from a-z ,traverse 2 times one for increasing part and other for decreasing part till size is greater tha zero. \n```\nclass Solution {\npublic:\n    string sortString(string s) {\n        int freq[26]={0};\n        int n=s.size();\n        for(int i=0 ; i<n ; i++)\n            freq[s[i]-\'a\']++;\n        string str="";\n        while(n>0)\n        {\n            for(int i=0 ; i<26 ; i++)\n            {\n                if(freq[i]>0)\n                {\n                    str+=(i+\'a\');\n                    n--;\n                    freq[i]--;\n                }\n            }\n            for(int i=25 ; i>=0 ; i--)\n            {\n                if(freq[i]>0)\n                {\n                    str+=(i+\'a\');\n                    n--;\n                    freq[i]--;\n                }\n            }\n                \n        }\n        return str;\n    }\n};\n```
[]