red red bulbs ('a') and blue blue bulbs ('b'). To keep three bulbs of one color from ending up in a row, it hangs them in portions:
- while both colors remain: if more red than blue bulbs are left, it hangs "aab"; if more blue are left, "bba"; if the counts are equal, "ab";
- once one color runs out, all the remaining bulbs of the other color go at the end.
Return the finished garland as a string of 'a' and 'b'. The input is such that three equal bulbs never end up in a row.red=5, blue=3 → 'aabaabab'
5 > 3, so 'aab' goes up, leaving 3 and 2. 3 > 2, another 'aab', leaving 1 and 1. Equal, so 'ab'. Result: 'aabaabab'.
red=1, blue=4 → 'bbabb'
More blue, so 'bba', leaving 0 and 2. Red is used up, so the two blue bulbs go at the end.
red=2, blue=0 → 'aa'
red=5, blue=3
'aabaabab'
Run checks the first 3 tests in your browser. Submit checks all 38 tests on the server, hidden ones included.