javascript greedy 192ms
Main idea: greedy.\nto make lexical greatest, so each time use out current largest char (search from end 25 -> 0)\n  (1) freq <= limit, append (freq char) direc
Main idea: greedy.\nto make lexical greatest, so each time use out current largest char (search from end 25 -> 0)\n  (1) freq <= limit, append (freq char) directly, f[i] = 0\n  (2) freq > limit, append (limit char), find a bridge (second largest char, to make lexical greatest), append it, f[i] -= limit,\n       until freq <= limit, redo (1)\n\t   if cannot find a bridge char, stop now is the answer\n```\nconst ord = (c) => c.charCodeAt();\n\nconst repeatLimitedString = (s, limit) => {\n    let f = Array(26).fill(0), res = \'\';\n    for (const c of s) f[ord(c) - 97]++;\n    for (let i = 25; ~i; i--) { // each time use out current largest char\n        if (f[i] == 0) continue;\n        let c = String.fromCharCode(97 + i);\n        while (f[i] > limit) { // condition 2\n            res += c.repeat(limit);\n            f[i] -= limit;\n            let findBridge = false, bridge, j;\n            for (j = 25; ~j; j--) { // find second larger char\n                if (j == i) continue; // should be different from current char\n                if (f[j] > 0) {\n                    findBridge = true;\n                    bridge = String.fromCharCode(97 + j);\n                    break;\n                }\n            }\n            if (!findBridge) return res;\n            res += bridge;\n            f[j]--;\n        }\n        res += c.repeat(f[i]); // condition 1\n        f[i] = 0;\n    }\n    return res;\n};\n```
['Greedy', 'JavaScript']