Simple O(n) C++
\nstring sortString(string s) {\n        vector<int>da(26,0);\n        int  cnt=0;\n        string  ans;\n        for(auto i:s)\n        {   \n            da[i-
```\nstring sortString(string s) {\n        vector<int>da(26,0);\n        int  cnt=0;\n        string  ans;\n        for(auto i:s)\n        {   \n            da[i-\'a\']++;\n            cnt++;\n        }\n        while(cnt)\n        {\n            for(int i=0;i<=25;i++)\n            {\n                if(da[i])\n                {\n                    da[i]--;\n                    ans+=\'a\'+i;\n                    cnt--;\n                }\n            }\n            for(int i=25;i>=0;i--)\n            {\n                if(da[i])\n                {\n                    da[i]--;\n                    ans+=\'a\'+i;\n                    cnt--;\n                }\n            }\n            cout<<cnt<<"\\n";\n        }\n        return ans;\n    }\n```
[]