Java 2ms 100% using Char Frequency Array O(N)
\npublic String sortString(String s) {\n\tchar[] chars = new char[26];\n\tStringBuilder sb = new StringBuilder();\n\n\tfor(char cc : s.toCharArray()) {\n\t\tcha
```\npublic String sortString(String s) {\n\tchar[] chars = new char[26];\n\tStringBuilder sb = new StringBuilder();\n\n\tfor(char cc : s.toCharArray()) {\n\t\tchars[cc - \'a\']++;\n\t}\n\n\tboolean picked = false;\n\n\tdo {\n\t\tpicked = false;\n\t\tfor(int i=0; i<chars.length; i++) {\n\t\t\tif(chars[i] > 0) {\n\t\t\t\tsb.append((char) (\'a\' + i));\n\t\t\t\tchars[i]--;\n\t\t\t\tpicked = true;\n\t\t\t}\n\t\t}\n\n\t\tif(!picked) break;\n\n\t\tpicked = false;\n\t\tfor(int i=chars.length-1; i>=0; i--) {\n\t\t\tif(chars[i] > 0) {\n\t\t\t\tsb.append((char) (\'a\' + i));\n\t\t\t\tchars[i]--;\n\t\t\t\tpicked = true;\n\t\t\t}\n\t\t}\n\n\t} while(picked = true);\n\n\treturn sb.toString();\n}\n```
[]