Problem. An image is an R × C grid of integer colours. Starting from pixel (sr, sc), recolour it and every pixel
connected to it (up, down, left, right) that has the same original colour, to new_color. Return the image.
image = 1 1 1 start (1, 1), new colour 2 2 2 2
1 1 0 2 2 0
1 0 1 2 0 1 (the bottom-right 1 isn't connected)
A grid is a graph: each pixel is a node, and edges join neighbouring pixels of the same colour. Flood fill is "find the connected component of one node", the simplest real use of BFS and DFS from lesson 11.1.
ML context. Region growing from a seed is a classic segmentation step: click a point, grow a mask over similar pixels (the "magic wand"), or clean up a predicted mask by filling holes and removing specks. Annotation tools, medical imaging and post-processing of segmentation models all run this, on images large enough that recursion fails (Change C).