Easy to understand | c++
\n// Using priority queue\n    string repeatLimitedString(string s, int k) {\n        string res = "";\n        \n        map<char,int> mp;\n        \n        f
```\n// Using priority queue\n    string repeatLimitedString(string s, int k) {\n        string res = "";\n        \n        map<char,int> mp;\n        \n        for(auto x:s)\n        {\n           mp[x]++;\n        }\n        \n        priority_queue<pair<char,int>> pq;\n        \n        for(auto x:mp)\n        {\n            pq.push({x.first,x.second});\n        }\n        \n        while(!pq.empty())\n        {\n            char c1 = pq.top().first;\n            int f1 = pq.top().second;\n            pq.pop();\n            \n            int len = min(k,f1);\n            \n            for(int i=0;i<len;i++)\n            {\n                res += c1;\n            }\n            \n            if(!pq.empty() and f1 - len > 0)\n            {\n                char c2 = pq.top().first;\n                int f2 = pq.top().second;\n                \n                pq.pop();\n                \n                res += c2;\n                if(f1 - len > 0)\n                {\n                    pq.push({c1,f1-len});\n                }\n                if(f2 - 1 > 0)\n                {\n                    pq.push({c2,f2-1});\n                } \n            }   \n            \n        }\n        return res;\n        \n    }\n```
['C', 'Heap (Priority Queue)']