[Java] Using char counting array with O(1) space
My easy-understanding solution, O(n) time complexity and O(26) -> O(1) space.\n\nclass Solution {\n    public String repeatLimitedString(String s, int repeatLim
My easy-understanding solution, O(n) time complexity and O(26) -> O(1) space.\n```\nclass Solution {\n    public String repeatLimitedString(String s, int repeatLimit) {\n        int[] counter = new int[26];\n        int max = 0;\n        for (char ch : s.toCharArray()) {\n            int curr = ch - \'a\';\n            max = Math.max(max, curr);\n            counter[curr]++;\n        }\n        int repeated = 0;\n        StringBuilder builder = new StringBuilder();\n        while (max >= 0) {\n            builder.append((char)(\'a\' + max));\n            counter[max]--;\n            repeated++;\n            if (counter[max] == 0) {\n                max = findNextMax(counter, max - 1);\n                repeated = 0;\n\t\t\t\tcontinue;\n            } \n            if (repeated == repeatLimit) {\n\t\t\t\t// Greedy, use the next possible char once and get back to curr.\n\t\t\t\t// if no other char available, the curr word is the largest subsequence. \n                int lower = findNextMax(counter, max - 1);\n                if (lower < 0) {\n                    return builder.toString();\n                }\n                builder.append((char)(\'a\' + lower));\n                counter[lower]--;\n                repeated = 0;\n            }\n        }\n        return builder.toString();\n    }\n    \n    private int findNextMax(int[] counter, int from) {\n        int curr = from;\n        while (curr >= 0) {\n            if (counter[curr] > 0) {\n                return curr;\n            }\n            curr--;\n        }\n        return curr;\n    }\n}\n```
['Counting', 'Java']