Java Easy to understand Solution Using TreeMap
\nclass Solution {\n    public String sortString(String s) {\n        int n = s.length();\n        TreeMap<Character,Integer> map = new TreeMap<>();\n        fo
```\nclass Solution {\n    public String sortString(String s) {\n        int n = s.length();\n        TreeMap<Character,Integer> map = new TreeMap<>();\n        for(char ch : s.toCharArray()){\n            map.put(ch , map.getOrDefault(ch,0)+1);\n        }\n        StringBuilder ans=new StringBuilder();\n        \n        while( n > 0 ){\n            \n            for(char ch:map.keySet()){\n                if(map.get(ch) > 0){\n                  ans.append(ch);\n                  map.put(ch,map.get(ch)-1);\n                  n--;\n                }\n            }\n            \n            StringBuilder rev = new StringBuilder();\n            \n            for(char ch:map.keySet()){\n               if(map.get(ch) > 0){\n                  rev.append(ch);\n                  map.put(ch,map.get(ch)-1);\n                  n--;\n                }\n             }\n            ans.append(rev.reverse());\n        }\n        return ans.toString();\n    }\n}\n```
['Tree']