My Java Solutions with comments and idea
\n// so the idea here is to first count the frequency of all charcaters present inside the given input text.\n// then we take the frequency.\n// until our resul
```\n// so the idea here is to first count the frequency of all charcaters present inside the given input text.\n// then we take the frequency.\n// until our resulting string < len(input string)\n    // first we go from a - > z and check whther we have a frequency > 0, if yes, then we uodate our result and decrease the frequency.\n    // same way, we do z -> a and check the same as above and append to the result.\n// finally this result will give us the answe according to the algorithm provided in the question.\n\nclass Solution {\n    public String sortString(String s) {\n        int [] freq = new int[26];\n        for (char ch: s.toCharArray()) {\n            freq[ch - \'a\'] += 1;\n        }\n        StringBuilder sb = new StringBuilder();\n        while (sb.length() < s.length()) {\n            for (int i=0; i<26; i++) {\n                if (freq[i] > 0) {\n                    sb.append((char) (i + \'a\'));\n                    freq[i] -= 1;\n                }\n            }\n            for (int i=25; i>=0; i--) {\n                if (freq[i] > 0) {\n                    sb.append((char) (i + \'a\'));\n                    freq[i] -= 1;\n                }\n            }\n        }\n        return sb.toString();\n    }\n}\n```
['String', 'Java']