text consists of lowercase English letters and digits. Rearrange its characters so that letters and digits strictly alternate: no two letters and no two digits stand next to each other.
To make the answer unique, follow these rules:
- the first character is of the kind that occurs more often; if there are as many letters as digits, a letter goes first;
- the letters keep the order they had in text, and so do the digits.
If no alternating arrangement exists, return an empty string.text="x7y8" → 'x7y8'
Two letters and two digits, an equal split, so we start with a letter: x7y8.
text="5ab90" → '5a9b0'
Three digits and two letters, so digits go first: 5a9b0. The digits keep their order (5, 9, 0) and so do the letters (a, b).
text="mn3" → 'm3n'
Two letters and one digit give m3n.
text consists of lowercase English letters and digitstext="x7y8"
'x7y8'
Run checks the first 3 tests in your browser. Submit checks all 139 tests on the server, hidden ones included.