Pattern Recognition Drill
Easy Advanced Graphs
The Problem
Change all connected cells of the same color starting from (sr, sc).
What approach would you use?
Think about it before scrolling down.
DFS from (sr, sc). Change color, recurse on 4 neighbors matching original color. O(m*n).
BFS from start pixel also works. Same O(m*n).
Common Trap
If new_color == original_color, return immediately — otherwise infinite recursion.