C++ Easy Thinking and Approach
\n Count all characters in 26 buckets (\'a\' to \'z\').\n While we have characters left:\n\t \tFind the largest bucket i with characters.\n\t \tPick up to limit
\n* Count all characters in 26 buckets (\'a\' to \'z\').\n* While we have characters left:\n\t* \tFind the largest bucket i with characters.\n\t* \tPick up to limit characters from that bucket.\n\t* \tFind the second largest bucket j with characters.\n\t* \tPick 1 character from the next largest bucket.\n\n\n```\n#define debug(x) cout<<#x<<":"<<x<<endl;\n    #define debug2(x,y) cout<<#x<<":"<<x<<"|"<<#y<<":"<<y<<endl;\n    string repeatLimitedString(string s, int repeatLimit) {\n        int arr[26] = {0};\n        for(auto& val:s){\n            arr[val-\'a\']++;\n        }\n        \n        // cout<<"["<<" ";\n        // for(int i = 0;i<=25;i++){\n        //     debug((char)(i+\'a\'),arr[i]);\n        // }\n        // cout<<"]"<<endl;\n        \n        string str = "";\n        int idx = 25;\n        \n        while(idx >= 0){\n            //debug(idx);\n            int rp = repeatLimit;\n            while(arr[idx] != 0 && rp){\n                str += (idx + \'a\');\n                //debug2(idx,str);\n                arr[idx]--;\n                //debug2(idx,arr[idx]);\n                rp--;\n            }\n            if(arr[idx] == 0){\n                idx--;\n                continue;\n            }\n            if(arr[idx] != 0){\n                if(idx != 0){\n                    int j = idx-1;\n                    //debug2(j,arr[j]);\n                    while(j >= 0 && arr[j] == 0) j--;\n                    //debug2(j,arr[j]);\n                    if(j < 0) break;\n                    str += (j+\'a\');\n                    arr[j]--;\n                }else{\n                    break;\n                }\n            }\n        }\n        return str;\n    }\n```
['Greedy', 'C', 'C++']