The Replace All ?'s to Avoid Consecutive Repeating Characters interview question gives you a string containing lowercase letters and '?' wildcards. You must replace each '?' with a lowercase letter such that no two adjacent characters in the resulting string are the same. Any valid replacement is acceptable — you just need to ensure no consecutive duplicates remain after all wildcards are filled.
Microsoft asks this problem to evaluate greedy character assignment under local constraints. It tests a candidate's ability to handle placeholder replacement while considering both left and right neighbors simultaneously. It is a practical exercise in constraint satisfaction, which applies to template filling, code generation, and string sanitization problems in real software systems.
The pattern is greedy character substitution with a small candidate set. For each '?' in the string, try characters 'a', 'b', 'c' in order. Pick the first one that differs from both the left neighbor (index i-1) and the right neighbor (index i+1). Since you only need to avoid two specific characters, at most three candidates are needed — one of 'a', 'b', 'c' is always safe by the pigeonhole principle.
Input: "?zz?"
'?'): left=none, right='z'. Try 'a': not 'z' → place 'a'.'?'): left='z', right=none. Try 'a': not 'z' → place 'a'.
Result: "azza".Input: "ab?ac":
'?'): left='b', right='a'. Try 'a': equals right neighbor. Try 'b': equals left neighbor. Try 'c': works!
Result: "abcac".'?' characters, which must remain unchanged.For the Replace All ?'s to Avoid Consecutive Repeating Characters coding problem, the string interview pattern is about local constraint satisfaction with minimal candidates. Prove why three letters suffice: at most two neighbors to avoid, three choices guarantee one is always valid. Microsoft interviewers appreciate when you articulate this reasoning before coding — it shows structured thinking over trial and error.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Reformat The String | Easy | Solve | |
| Check if All A's Appears Before All B's | Easy | Solve | |
| Number of Segments in a String | Easy | Solve | |
| Detect Capital | Easy | Solve | |
| Score of a String | Easy | Solve |