canvas, where canvas[i][j] is a pixel's color. The user clicks the paint bucket with color paint on the pixel at row row and column col.
The bucket recolors that pixel to paint, together with every pixel of the same original color reachable from it by stepping between side-adjacent neighbors (up, down, left, right) through pixels of that color only. Diagonal neighbors do not count.
Return the picture after the fill.canvas=[[3, 3, 0], [0, 3, 3], [3, 0, 3]], row=0, col=1, paint=7 → [[7, 7, 0], [0, 7, 7], [3, 0, 7]]
From cell (0, 1) the 3s at (0,0), (0,1), (1,1), (1,2), (2,2) are joined by sides and become 7. The 3 at (2,0) touches them only by a corner and stays.
canvas=[[5, 5], [5, 5]], row=1, col=0, paint=5 → [[5, 5], [5, 5]]
The paint matches the area's color, so nothing changes.
canvas=[[1, 2, 1]], row=0, col=2, paint=0 → [[1, 2, 0]]
canvas=[[3, 3, 0], [0, 3, 3], [3, 0, 3]], row=0, col=1, paint=7
[[7, 7, 0], [0, 7, 7], [3, 0, 7]]
Run checks the first 3 tests in your browser. Submit checks all 91 tests on the server, hidden ones included.