FunctionRacerProblemsRace

Paint Bucket

EasyGraphsPython, JavaScript, TypeScript, Java, C++

picture is a rectangular grid of integers given as a list of rows; each integer is a colour code. A paint-bucket click lands on the cell at row row, column col (both 0-based). The click repaints that cell and every cell that can be reached from it by moving up, down, left or right through cells holding the same colour as the clicked cell had; all of those cells get colour color. Diagonal neighbours do not connect.

Return the grid after the click. If the clicked cell already has colour color, nothing changes. You may change picture in place or build a new grid; only the returned grid is checked.

Example 1

picture [[1,1,0],[1,0,0],[2,2,1]]
row 0
col 0
color 5
returns [[5,5,0],[5,0,0],[2,2,1]]

The clicked 1 at the top left is joined to the 1 below it and the 1 to its right; the 1 at the bottom right is not connected, so it stays.

Example 2

picture [[3,3],[3,3]]
row 1
col 1
color 3
returns [[3,3],[3,3]]

The clicked cell already holds colour 3, so the picture is unchanged.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Graphs problems