Flood Fill
You are given an m x n integer image, a start cell (sr, sc), and a new color. Starting from that cell, recolor every cell that is reachable from (sr, sc) by…
You are given an `m x n` integer image, a start cell `(sr, sc)`, and a new color. Starting from that cell, recolor every cell that is reachable from `(sr, sc)` by moving up, down, left, or right only, crossing cells that currently hold the same color as the start cell. Return the recolored image. If the start cell already holds the new color, return the image unchanged.
- `1 <= m, n <= 50` - `0 <= image[i][j] <= 65535` - `0 <= color <= 65535` - `0 <= sr < m` - `0 <= sc < n` - The interactive visualizer accepts images up to 12x12; larger valid images are execution-only.
Example 1: input image = [[1,1,1],[1,1,0],[1,0,1]], sr = 1, sc = 1, color = 2; output [[2,2,2],[2,2,0],[2,0,1]]. The four-neighbour region around (1, 1) is recolored; the lone 1 at the bottom-right corner is only diagonal to the region, so it keeps its value.
Example 2: input image = [[0,0,0],[0,0,0]], sr = 0, sc = 0, color = 0; output [[0,0,0],[0,0,0]]. The start cell already holds the new color, so there is nothing to recolor.
Category: Graphs. Topic: graph. Difficulty: Easy. Patterns: graph-traversal.