a, b and c in which no two neighbouring letters are equal. For example, acb, b and cacbab qualify, while bb and abcc do not.
List all such strings of length length in alphabetical order and number them starting from one. Return the string with number rank. If there are fewer than rank strings, return an empty string.length=2, rank=4 → 'bc'
The strings of length 2 in alphabetical order are ab, ac, ba, bc, ca, cb. The fourth one is bc.
length=4, rank=7 → 'acba'
The strings starting with a are abab, abac, abca, abcb, acab, acac, acba, acbc; the seventh is acba.
length=3, rank=13 → ''
There are only 3 · 2 · 2 = 12 such strings of length 3, so there is no thirteenth.
length=2, rank=4
'bc'
Run checks the first 3 tests in your browser. Submit checks all 79 tests on the server, hidden ones included.