JAVA | Simple Solution | Frequency Table
Code
\n# Code\n```java []\nclass Solution {\n    public String repeatLimitedString(String s, int repeatLimit) {\n        int [] vocab = new int[26];  //frequency table\n        for (char ch : s.toCharArray()) vocab[ch - \'a\']++;\n        StringBuilder sb = new StringBuilder();\n        int idx = 25;\n        while (idx >= 0) {\n            if (vocab[idx] == 0) {\n                idx--;\n                continue;\n            }\n            int count = Math.min(vocab[idx], repeatLimit);\n            for (int i = 0 ; i < count ; i++) sb.append((char)(idx + \'a\'));\n            vocab[idx] -= count;\n            if (vocab[idx] > 0) {  //if there exists more characters than \'repeatLimit\'\n                int next = idx - 1;\n                while (next >= 0 && vocab[next] == 0) next--;  //retriving the next largest idx \n                if (next < 0) break;\n                sb.append((char) (next + \'a\')); //adding 1 character from the next largest idx\n                vocab[next]--;\n            }\n        }\n        return sb.toString();\n    }\n}\n```
['Hash Table', 'String', 'Counting', 'Java']