Alternating Paint Recovery
Preview mode. Log in to edit, run, submit, and save progress.
Alternating Paint Recovery
A damaged paint log contains cells marked R, B, and ?. Known R and B cells must remain unchanged. The recovery scanner fills unknown cells using a fixed rule: if the entire string is unknown, it starts with B and alternates colors from left to right; otherwise, it finds the first known color, fills unknown cells to its left so neighboring recovered cells alternate, and then scans to the right, replacing each ? with the opposite of the immediately previous cell. Existing known cells are never changed. For each paint log, output the recovered stripe. Input Format: The first line contains t, the number of test cases. Each test case contains n and a stripe string of length n. Output Format: For each test case, print the recovered stripe.
Examples
1 5 R?B??
RBBRB
Explanation: The first known color is the leading R. Scanning right changes the first ? to B, keeps the existing B, then fills the remaining cells as R and B.
Approach hint
Start with the simplest clear approach, explain the trade-off, then move toward the cleaner answer.
Common mistake
Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.