Flood Fill
Try to solve the Flood Fill problem.
We'll cover the following
Statement#
We are given the following values as input to begin with:
The coordinates of a source cell, i.e.,
srandsc.A target value,
target.An
grid.
Our task is to perform flood fill by updating the values of the four directionally connected cells, which have the same value as the source cell with the target value.
How to perform flood fill:
Suppose that a
If no neighboring cell has a value equal to the source cell, only update the source cell with the target value and return the updated grid.
Constraints:
grid.length,grid[i].lengthgrid[i][j],targetsrgrid.lengthscgrid[i].length
Examples#
1 of 3
2 of 3
3 of 3
Understand the problem#
Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:
Flood Fill
What is the correct output for the following input values?
Figure it out!#
We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.
Try it yourself#
Implement your solution in the following coding playground:
Solution: Word Search
Solution: Flood Fill