You are given an image represented by an m x n grid of integers image, where image[i][j] represents the pixel value of the image. You are also given three integers sr, sc, and color. Your task is to perform a flood fill on the image starting from the pixel image[sr][sc]. To perform a flood fill: begin with the starting pixel and change its color to color. Perform the same process for each pixel that is directly adjacent (4-directionally) and shares the same color as the starting pixel. Keep repeating this process until there are no more adjacent pixels of the original color. Return the modified image.
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]]
Explanation: Starting from (1,1), the fill spreads to every 1 connected up, down, left or right: the whole top row, (1,0), (1,1) and (2,0). The 1 at (2,2) is walled off by 0s, so it keeps its colour.
Example 2
Input: image = [[0,0,0],[0,0,0]], sr = 0, sc = 0, color = 0
Output: [[0,0,0],[0,0,0]]
Explanation: The start pixel already has the colour 0, so the fill changes nothing.
Example 3
Input: image = [[1]], sr = 0, sc = 0, color = 3
Output: [[3]]
Explanation: The single pixel is repainted from 1 to 3.
Recolor the starting pixel and flood outward to 4-connected neighbours that share the original color, stopping at different colors or the border.
Run checks all cases above. Submit evaluates all test cases.