Flood Fill

easy
Unit 7 · BFS I0/4 to milestone

Implement flood_fill(image, r, c, color): change the pixel at (r, c) and every pixel connected to it (up/down/left/right) that has the same original color to color. Return a new image (don't modify the input), and use an explicit stack so large regions don't hit the recursion limit.

Also implement count_regions(image): the number of connected same-color regions.

#dfs#grids2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Flood Fill · TechGradify