Beginner Friendly || C++ || Priority Queue :)
Count Character Frequencies:
Use an unordered map mp to store the frequency of each character in the string s.
Max Heap (Priority Queue):
Push all characters an
**Count Character Frequencies:**\n- Use an unordered map mp to store the frequency of each character in the string s.\n\n---\n\n\n**Max Heap (Priority Queue):**\n- Push all characters and their frequencies into a max heap (priority queue), sorting by character value. (lexographical)\n\n---\n\n\n**Construct Result:**\n\n- While the heap is not empty, pick the top character with the highest value.\n- Append it to the result string repeatLimit times (or until its frequency runs out).\n- If the frequency remains and another character exists in the heap, pick the next highest character, append it once, and push back both updated counts into the heap.\n\n---\n\n\n**Handle Repeat Limit:**\n- The logic ensures no character repeats more than repeatLimit times consecutively by switching to the second character when needed.\n\n---\n\n\n**Return Result:**\n- The final string is returned once all characters are processed.\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    string repeatLimitedString(string s, int repeatLimit) {\n\n        unordered_map<char,int>mp;\n        for(char x: s) mp[x]++;\n\n        priority_queue<pair<char,int>>q;\n        for(auto x:mp) q.push({x.first,x.second});\n        \n        string result="";\n\n        while(!q.empty()){\n            auto x =q.top();\n            q.pop();\n            char c=x.first;\n            int cnt=x.second;\n            int limit=repeatLimit;\n            while(limit--){\n                result+=c;\n                cnt--;\n                if(cnt==0) break;\n            }\n            if(q.empty()) return result;\n            if(cnt>0){\n                auto y =q.top();\n                q.pop();\n                char d=y.first;\n                int cn=y.second;\n                result+=d;\n                if(cn-1>0)q.push({d,cn-1});\n                q.push({c,cnt});\n            }\n        }\n        return result;\n    }\n};\n```
['Hash Table', 'String', 'Heap (Priority Queue)', 'Counting', 'C++']