3 × 3 image · new colour 2
1
1
1
1
1
0
1
0
1
Recursive DFS flood
▸1oldColor = image[sr][sc]2if oldColor == newColor: return image3dfs(r, c):4 image[r][c] = newColor5 if out of bounds: return6 if image[nr][nc] != oldColor: skip7 dfs(nr, nc) // each of 4 neighbours8dfs(sr, sc); return image
state
- start(1, 1)
- oldColor1
- newColor2