Flood Fill Algorithm
00:00
AmazonAdobe
Given an image (2D grid), a starting pixel, and a new color, perform flood fill. Change the starting pixel and all 4-directionally connected pixels of the same original color to the new color.
Examples
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]]
Input → image=[[0,0,0],[0,0,0]], sr=0,sc=0, color=0
Output → [[0,0,0],[0,0,0]]
Note: same color