JAVA | Faster than 100% | Clean Code
```\nclass Solution {\n    public String sortString(String s) {\n        StringBuilder res = new StringBuilder();\n        int arr[] = new int[26], total = s.le
```\nclass Solution {\n    public String sortString(String s) {\n        StringBuilder res = new StringBuilder();\n        int arr[] = new int[26], total = s.length();\n        for(char c : s.toCharArray())\n            arr[c-\'a\']++;\n        while(total > 0){\n            int smallest = 0, largest = 25;\n            while(smallest < 26 && arr[smallest] == 0)\n                smallest++;\n            while(smallest < 26){\n                if(arr[smallest] != 0){\n                    res.append((char)(\'a\'+smallest));\n                    arr[smallest]--;\n                    total--;\n                }\n                smallest++;\n            }\n            while(largest >=0 && arr[largest] == 0)\n                largest--;\n            while(largest >= 0){\n                if(arr[largest] != 0){\n                    res.append((char)(\'a\'+largest));\n                    arr[largest]--;\n                    total--;\n                }\n                largest--;\n            }\n        }\n        return res.toString();\n    }\n}\n\n- Do Upvote if this helps \u2B06\uFE0F \uD83D\uDC4D\uD83C\uDFFB
['Java']