Simple TreeMap java
\n    public String sortString(String s) {\n        StringBuilder sb = new StringBuilder();\n        TreeMap<Character, Integer> charMap = new TreeMap<>();\n   
```\n    public String sortString(String s) {\n        StringBuilder sb = new StringBuilder();\n        TreeMap<Character, Integer> charMap = new TreeMap<>();\n        for(char c: s.toCharArray()) charMap.put(c, charMap.getOrDefault(c, 0) +1);\n        \n        int index = 0;\n        while (true){\n            StringBuilder current = new StringBuilder();\n            for(Character c : charMap.keySet()){\n                if(charMap.get(c) !=0) {\n                    current.append(c);\n                    charMap.put(c, charMap.getOrDefault(c, 0) - 1);\n                }\n            }\n            if("".equals(current.toString())) break;\n            if(index++ % 2 ==0) sb.append(current);\n            else sb.append(current.reverse());\n        }\n        return sb.toString();\n    }\n```
[]