letters and a number max_run. Build a new string from these letters in which no letter repeats more than max_run times in a row. You do not have to use every letter, but each letter of letters can be used at most once.
Return the lexicographically largest such string. String a is larger than b if, at the first position where they differ, a has the letter later in the alphabet; if one string is a prefix of the other, the longer one is larger.letters="yxyyy", max_run=2 → 'yyxyy'
We would like all four y in a row, but at most two are allowed. So we get yy, then x as a separator, then the remaining yy: "yyxyy".
letters="cccca", max_run=1 → 'cac'
Every c needs a separator after it, and there is only one, a. The result is "cac"; the remaining c letters cannot be used.
letters="bab", max_run=3 → 'bba'
letters consists of lowercase English lettersletters="yxyyy", max_run=2
'yyxyy'
Run checks the first 3 tests in your browser. Submit checks all 68 tests on the server, hidden ones included.