C++ | Easy to understand | Hash Map
\nclass Solution {\npublic:\n    string repeatLimitedString(string s, int repeatLimit) {\n        vector<int> cnt(26, 0);\n        for(auto &x : s){\n          
```\nclass Solution {\npublic:\n    string repeatLimitedString(string s, int repeatLimit) {\n        vector<int> cnt(26, 0);\n        for(auto &x : s){\n            cnt[x-97]++;\n        }\n        \n        string ans = "";\n        int j = 25;\n        while(j>=0 and cnt[j]==0){\n            j--;\n        }\n        j--;\n        \n        for(int i=25; i>=0; i--){\n            int tmp = repeatLimit;\n            while(cnt[i]>0 and tmp>0){\n                ans.push_back(i+97);\n                cnt[i]--;\n                tmp--;\n            }\n            if(cnt[i] != 0){\n                while(j>=0 and (cnt[j]==0 or j==i)){\n                    j--;\n                }\n                if(j>=0){\n                    ans.push_back(j+97);\n                    cnt[j]--;\n                    i++;\n                }\n            }\n        }\n        \n        return ans;\n    }\n};\n```
[]