FunctionRacerProblemsRace

Reformat the String

EasyStringsPython, JavaScript, TypeScript, Java, C++

s has lowercase letters and digits. Rearrange it so that no two letters are next to each other and no two digits are next to each other. To make the answer unique, use the letters in the order they appear in s and the digits in the order they appear in s, and begin with whichever kind there is more of (begin with a letter if the counts are equal).

Return the result, or an empty string if no such arrangement exists.

Example 1

s "a0b1c2"
returns "a0b1c2"

Equal counts, start with a letter: a0b1c2.

Example 2

s "abc12"
returns "a1b2c"

More letters, start with a letter: a1b2c.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Strings problems