DFS from start pixel. Change color and recurse to neighbors.
function floodFill(image, sr, sc, color): original = image[sr][sc] if original == color: return image def dfs(r, c): if r < 0 or r >= len(image) or c < 0 or c >= len(image[0]): return if image[r][c] != original: return image[r][c] = color dfs(r-1, c) dfs(r+1, c) dfs(r, c-1) dfs(r, c+1) dfs(sr, sc) return image
time.