[Java] No nested loops simple fast solution
Runtime: 2 ms, faster than 100.00% of Java online submissions for Increasing Decreasing String.\nMemory Usage: 39.4 MB, less than 100.00% of Java online submiss
Runtime: 2 ms, faster than 100.00% of Java online submissions for Increasing Decreasing String.\nMemory Usage: 39.4 MB, less than 100.00% of Java online submissions for Increasing Decreasing String.\n\n1. Calculates frequency of each character and puts it into counts map;\n2. Depends on the direction goes back and forth through the counts map and pick the available character.\n\n\n```\npublic String sortString(String s) {\n    int[] cs = new int[26];\n\n    for (char c : s.toCharArray()) {\n        cs[c - \'a\']++;\n    }\n\n    int n = s.length();\n    int i = 0;\n    int dir = 1;\n\tStringBuilder result = new StringBuilder();\n    while (n > 0) {\n        if (i < 0) {\n            dir = 1;\n        } else if (i == cs.length) {\n            dir = -1;\n        } else if (cs[i] > 0) {\n            cs[i]--;\n            n--;\n\n            result.append((char)(\'a\' + i));\n        }\n\n        i += dir;\n    }\n\n    return result.toString();\n}\n```
['Java']