#1576

Replace All ?'s to Avoid Consecutive Repeating Characters

pupil · 490 · lc easy +27 · verified · 45.2% accepted · 603 likes · top 28%

Description

Given a string s of lowercase letters and '?' characters, replace every '?' with a lowercase letter so the final string contains no two consecutive identical characters. Non-'?' characters cannot be changed. Return any valid result string.

Example 1:

Input: s = "?zs"
Output: "azs"
Explanation: There are 25 solutions for this problem. From "azs" to "yzs", all are valid. Only "z" is an invalid modification as the string will consist of consecutive repeating characters in "zzs".

Example 2:

Input: s = "ubv?w"
Output: "ubvaw"
Explanation: There are 24 solutions for this problem. Only "v" and "w" are invalid modifications as the strings will consist of consecutive repeating characters in "ubvvw" and "ubvww".

Code

1
2
3