JAVA Solution: Simple Use of HashMap with explanation
\nclass Solution {\n    public String sortString(String s) {\n            HashMap<Character, Integer> map= new HashMap<>();\n             StringBuilder sb= new 
```\nclass Solution {\n    public String sortString(String s) {\n            HashMap<Character, Integer> map= new HashMap<>();\n             StringBuilder sb= new StringBuilder();\n            \n            //Count the frequency of each character.\n        for(char ch: s.toCharArray())\n            map.put(ch, map.getOrDefault(ch,0)+1);  \n            \n                 //Repeat until the frequency of all characters becomes zero\n            while(map.size()>0){\n                    //Loop over all character from \'a\' to \'z\' \n               for(int i=0; i<26; i++){\n                    char ch= (char)(97+i);\n                    //append the character if it exists \n                    if(map.containsKey(ch)) {\n                            sb.append(ch);\n                    //and decrease frequency by 1\n                      map.put(ch, map.get(ch)-1);\n                       if(map.get(ch)==0) \n                               map.remove(ch);     \n                    }\n               } \n                    //Loop over all character from \'z\' to \'a\' \n               for(int i=25; i>=0; i--){\n                    char ch= (char)(97+i);\n                    //append the character if it exists \n                    if(map.containsKey(ch)) {\n                            sb.append(ch);\n                    //and decrease frequency by 1\n                      map.put(ch, map.get(ch)-1);\n                       if(map.get(ch)==0)\n                               map.remove(ch);     \n                    } \n               }\n            }\n        return sb.toString();\n    }\n}\n```
['Java']