FunctionRacerProblemsRace

Replace All ?'s to Avoid Consecutive Repeating Characters

EasyStringsPython, JavaScript, TypeScript, Java, C++

s has lowercase letters and ? characters. Replace every ? by a lowercase letter so that no two neighbouring characters are equal. Scan from left to right and for each ? use the smallest letter that differs from both of its neighbours (the left neighbour is already final, the right neighbour is as given).

Return the resulting string.

Example 1

s "?zs"
returns "azs"

a is different from z.

Example 2

s "a?a?a"
returns "ababa"

Each ? sees a on both sides, so it becomes b.

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