Greedy + Priority Queue || Easy solution C++
\nclass Solution {\npublic:\n    string repeatLimitedString(string s, int k) \n    {\n        int n=s.size(),i;\n        priority_queue <pair<char,int>> q;\n   
```\nclass Solution {\npublic:\n    string repeatLimitedString(string s, int k) \n    {\n        int n=s.size(),i;\n        priority_queue <pair<char,int>> q;\n        vector <int> a(26);\n        for(auto x : s)\n        {\n            a[x-\'a\']++;\n        }\n        for(i=0;i<26;i++)\n        {\n            if(a[i]>0)\n            {\n                q.push({i+\'a\',a[i]});\n            }\n        }\n        string ans="";\n        while(!q.empty())\n        {\n            auto f=q.top();\n            q.pop();\n            if(f.second>k)\n            {\n                for(i=0;i<k;i++)\n                {\n                    ans.push_back(f.first);\n                }\n                f.second-=k;\n                if(!q.empty())\n                {\n                    auto sec=q.top();\n                    q.pop();\n                    sec.second--;\n                    ans.push_back(sec.first);\n                    if(sec.second>0)\n                    {\n                        q.push({sec.first,sec.second});\n                    }\n                }\n                else\n                {\n                    break;\n                }\n                q.push({f.first,f.second});\n            }\n            else\n            {\n                for(i=0;i<f.second;i++)\n                {\n                    ans.push_back(f.first);\n                }\n            }\n        }\n        return ans;\n    }\n};\n```
['Greedy', 'C', 'Heap (Priority Queue)']