Dodomeki
Sign in

33. Flood Fill by Region

Easy

Given an image as a matrix of colors, a starting position, and a new color, return a new matrix where the region at the starting position has been recolored; the region includes only side-connected cells that had the original color.

Example 1
Input: imagem = [[1,1,1],[1,1,0],[1,0,1]], linha = 1, coluna = 1, cor = 2
Output: [[2,2,2],[2,2,0],[2,0,1]]
Example 2
Input: imagem = [[0,0],[0,0]], linha = 0, coluna = 0, cor = 3
Output: [[3,3],[3,3]]
Constraints
  • 1 <= linhas, colunas <= 50
  • The colors are non-negative integers.
GraphsBFSMatrix
Caso 1
imagem =
[[1,1,1],[1,1,0],[1,0,1]]
linha =
1
coluna =
1
cor =
2
Expected =
[[2,2,2],[2,2,0],[2,0,1]]
Caso 2
imagem =
[[0,0],[0,0]]
linha =
0
coluna =
0
cor =
3
Expected =
[[3,3],[3,3]]

Run checks these 2 cases. Submit runs all 6, including hidden ones.