count_a letters a, count_b letters b and count_c letters c. You lay them out into a string one letter at a time, and the string must never contain three equal letters in a row.
Build the string greedily, step by step:
1. Among the letters still left, take the one with the most copies remaining. On a tie, take the one that comes first alphabetically.
2. If it would make three equal letters in a row, take instead the best of the other remaining letters by the same rule. If no other letter is left, the string is finished.
3. Append the chosen letter and repeat until the letters run out.
Return the resulting string. Think about why this greedy strategy produces a string of the greatest possible length.count_a=1, count_b=1, count_c=5 → 'ccaccbc'
Place "cc"; a third c is not allowed, so take a (a and b are tied and a comes first). Then "cc" again, then b and the last c.
count_a=0, count_b=6, count_c=1 → 'bbcbb'
After "bbcbb" only b is left and a third b in a row is not allowed, so the string ends with two b unused.
count_a=2, count_b=2, count_c=2 → 'abcabc'
count_a=1, count_b=1, count_c=5
'ccaccbc'
Run checks the first 3 tests in your browser. Submit checks all 94 tests on the server, hidden ones included.