faster than 80% of user's runtime
Code
\n\n# Code\n```java []\nclass Solution {\n    public String repeatLimitedString(String s, int repeatLimit) {\n        int[] freq = new int[26];\n\n        for (char c : s.toCharArray())\n            freq[c - \'a\']++;\n\n        int pendingLetterIndex = -1;\n        StringBuilder sb = new StringBuilder();\n\n        for (int i = 25; i >= 0; i--) {\n            if (freq[i] == 0)\n                continue;\n\n            if (pendingLetterIndex > 0) {\n                sb.append((char) (\'a\' + i));\n                freq[i]--;\n                i = pendingLetterIndex;\n                pendingLetterIndex = -1;\n\n            } else {\n                for (int j = 0; j < repeatLimit && freq[i] > 0; j++, freq[i]--)\n                    sb.append((char) (\'a\' + i));\n\n                if (freq[i] > 0)\n                    pendingLetterIndex = i + 1;\n            }\n        }\n        \n        return sb.toString();\n    }\n}\n```
['Hash Table', 'String', 'Greedy', 'Heap (Priority Queue)', 'Counting', 'Java']