Java beats 100% of both time and space
```\npublic String sortString(String s) {\n        StringBuilder res = new StringBuilder(s.length());\n        int[] letterCount = new int[26];\n        int sLe
```\npublic String sortString(String s) {\n        StringBuilder res = new StringBuilder(s.length());\n        int[] letterCount = new int[26];\n        int sLength = s.length();\n        \n        // populate letter count array\n        for(char c : s.toCharArray())\n        {\n            letterCount[c - \'a\']++;\n        }\n        \n        while(sLength != 0)\n        {\n            // move forward and append characters to res\n            for(int i=0; i<letterCount.length; i++)\n            {\n                if(letterCount[i] != 0)\n                {\n                    char c = (char) (\'a\' + i);\n                    res.append(c);\n                    letterCount[i]--;\n                    sLength--;\n                }\n            }\n            \n            // move backwards and append characters to res\n            for(int i=letterCount.length-1; i>=0; i--)\n            {\n                if(letterCount[i] != 0)\n                {\n                    char c = (char) (\'a\' + i);\n                    res.append(c);\n                    letterCount[i]--;\n                    sLength--;\n                }\n            }\n        }\n        \n        return res.toString();\n    }
[]