max heap || easy to understand || must see
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n//for fast io\nstatic int fast_io = []() \n{ \n    std::ios::sync_with_stdio(false); \n    cin.tie(nullptr); \n    cout.tie(nullptr); \n    return 0; \n}();\n\n#ifdef LOCAL\n    freopen("input.txt", "r" , stdin);\n    freopen("output.txt", "w", stdout);\n#endif\n\n//actual code begins here\nclass Solution {\npublic:\n    string repeatLimitedString(string s, int k) \n    {\n         //final constructed string to be returned from this function\n         string ans = "";\n\n         //first of all we will take the mapping of the char from string\n         unordered_map<char,int>mp;\n\n         //taking the mapping of the every char to keep that in heap\n         for(int i=0;i<s.length();i++)\n         {\n             char ch = s[i];\n             mp[ch]++;\n         }\n\n         //priority queue for keeping the large char on the top\n         priority_queue<pair<char,int>>pq;\n\n         for(auto it = mp.begin() ; it!=mp.end() ; it++)\n         {\n              char ch = it->first;\n              int freq = it->second;     \n              pq.push(make_pair(ch,freq));\n         }\n         //building the string according to the given constraint\n         while(!pq.empty())\n         {\n             pair<char,int>p1 = pq.top();\n             pq.pop();\n             char ele1 = p1.first;\n             int freq1 = p1.second;\n\n             if(freq1 < k)\n             {\n                 //appending ch1 freq1 times to the current answer\n                 while(freq1 > 0)\n                 {\n                     ans.push_back(ele1);\n                     freq1--;\n                 }\n             }\n             else if(freq1 == k)\n             {\n                 //appending ch1 freq1 times to the current answer\n                 while(freq1 > 0)\n                 {\n                     ans.push_back(ele1);\n                     freq1--;\n                 }\n             }\n             else if(freq1 > k)\n             {\n                  //appending ch1 freq1 times to the current answer\n                  int temp = k;\n                  while(temp > 0)\n                  {\n                     ans.push_back(ele1);\n                     temp--;\n                  }\n                  freq1 = freq1 - k;\n                  \n                  //breaking the streak of the k characters\n                  \n                  //if we do not have any one to break the freq of the curr char then break\n                  if(pq.size() == 0)\n                  break;\n\n                  //else we have someone that can break the freq of the curr char\n                  pair<char,int>p2 = pq.top();\n                  pq.pop();\n                  char ele2 = p2.first;\n                  int freq2 = p2.second;\n                  \n                  if(freq2 > 0)\n                  {\n                      ans.push_back(ele2);\n                      freq2--;\n                      \n                      if(freq2 > 0)\n                      pq.push(make_pair(ele2,freq2));\n                  }\n                  if(freq1 > 0)\n                  pq.push(make_pair(ele1,freq1));\n             }\n         }\n         return ans;\n    }\n};\n```
['String', 'Greedy', 'Heap (Priority Queue)', 'Counting', 'C++']