You’re developing a one-player game for people to pass the time with. The player is given a grid of tiles from 0 to 9 like this:
4 4 4 4
5 5 5 4
2 5 7 5
The player selects one of these tiles, and that tile will disappear, along with all the connected tiles of the same number. Tiles can be connected adjacently up, down, left, or right.
Write a function that takes in a grid of tiles, and the row and column indexes of a selected tile on the grid, and returns the number of tiles that will disappear.
The grid is guaranteed to be rectangular. All values in the grid will be integers between 0 and 9. The input row and column are zero-indexed integers, and will always be on the grid.