Java Simple Beats 100 percent
calculates freq of each character\n Step 1: If accumulated all characters, we are done, else\n Step 2: accumulate from \'a\' -> \'z\', \n Step 3: accumulate fro
* calculates freq of each character\n* Step 1: If accumulated all characters, we are done, else\n* Step 2: accumulate from \'a\' -> \'z\', \n* Step 3: accumulate from \'z\' -> \'a\'\n* Go to Step 1.\n\n\n```\npublic String sortString(String s) {\n        int len = s.length();\n        int[] freq = new int[26];\n        for (int index = 0; index < len; index++) {\n            freq[s.charAt(index) - \'a\']++;\n        }\n        StringBuilder sb = new StringBuilder(len);\n        int count = 0;\n        while (count < len) {\n            // sorting up\n            for (int i = 0; i < 26; i++) {\n                if (freq[i] > 0) {\n                    sb.append((char) (i + \'a\'));\n                    freq[i] = freq[i] - 1;\n                    count++;\n                }\n            }\n            // sorting down\n            for (int i = 25; i >= 0; i--) {\n                if (freq[i] > 0) {\n                    sb.append((char) (i + \'a\'));\n                    freq[i] = freq[i] - 1;\n                    count++;\n                }\n            }\n        }\n        return sb.toString();\n    }\n```\n\nPlease vote up if you like the solution as encouragement!\n
[]