Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Use DFS from the start cell. If a neighbor has the same original color, recolor it and continue. Guard against bounds and same-color checks to stop recursion.
All reachable cells with the original color are part of the same connected component, so recursive paint marks exactly that component once.
Updated Feb 2026