Easy Solution using map for beginners !!!
IntuitionWe want to build a string by repeating characters from the input string s, but no character should appear more than k times consecutively. The idea is
# Intuition\nWe want to build a string by repeating characters from the input string s, but no character should appear more than k times consecutively. The idea is to always pick the largest available character and add it to the result, respecting the k limit. If a character appears more than k times, we handle it by inserting the next largest character.\n\n# Approach\n1) Count character frequencies using a map to store how many times each character appears in the string.\n2) **Greedy selection**: Always pick the largest character available, adding it to the result up to k times.\n3) **Handle remaining characters**: If a character appears more than k times, we add the next largest character once and then put that character in map and reduce the count by 1 then put the original character back with its reduced count.\n4) Repeat this process until all characters are added to the result.\n\n# Complexity\n- Time complexity:\nO(nlogm), where n is the length of the string, and m is the number of unique characters.\n\n- Space complexity:\nO(m), where m is the number of unique characters in the string.\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    \n    string repeatLimitedString(string s, int k) {\n        map<char , int > mp;\n        string ans = "";\n        for(auto it : s){\n            mp[it]++;\n        }\n        while(mp.size()>0){\n            auto it = mp.rbegin();\n            char hj = it->first;\n            int co = it->second;\n            int num = min(co , k);\n            while(num--){\n                ans += hj;\n            }\n            mp.erase(hj);\n            bool flag = true;\n            if(co>k && mp.size()>0){\n                flag = false;\n                it = mp.rbegin();\n                char ch = it->first;\n                int nu = it->second;\n                mp.erase(ch);\n                ans += ch;\n                nu--;\n                if(nu>0){\n                    mp[ch] = nu;\n                }\n            }\n            if(co>k && !flag){\n                mp[hj] = co - k;\n            }\n        }\n       \n        return ans;\n    }\n};\n```
['Hash Table', 'String', 'Greedy', 'Counting']