class Solution: def __init__(self): self.V = list() def bfs(self,grid,color,rows,coloums,r,c,ocolor): cur = [r,c] if cur[0]-1 >=0 and self.V[cur[0]-1][cur[1]]==0 and grid[cur[0]-1][cur[1]]==ocolor: grid[cur[0]-1][cur[1]] = color self.V[cur[0]-1][cur[…