[C++] O(n) easy to understand.
\nclass Solution {\npublic:\n    string repeatLimitedString(string s, int repeatLimit) {\n        int cnt[26] = {0};\n        \n        for (auto c : s) {\n    
```\nclass Solution {\npublic:\n    string repeatLimitedString(string s, int repeatLimit) {\n        int cnt[26] = {0};\n        \n        for (auto c : s) {\n            ++cnt[c - \'a\'];\n        }\n        \n        string ans;\n        int prevsize = -1;\n        \n        int k = 0;\n        while (ans.size() < s.size()) {            \n            for (int i = 25; i >= 0; --i) {\n                \n                if (cnt[i] == 0) {\n                    continue;\n                }\n                \n                if ((i + \'a\') == ans.back() && k == repeatLimit) {\n                    continue;\n                }\n                \n                k = (i + \'a\') == ans.back() ? k + 1 : 1;\n                \n                ans.push_back((i + \'a\'));\n                --cnt[i];\n                break;\n            }\n            \n            if (prevsize == ans.size()) {\n                break;\n            }\n            \n            prevsize = ans.size();\n        }\n         \n        return ans;\n    }\n};\n```
[]