CodeOath
← All problems

Flood Fill

Easy
graphsdfsmatrix

You're given an image (2D grid of integers), a starting pixel (sr, sc), and a color.

Perform a flood fill starting at (sr, sc): change the color of that pixel and every pixel 4-directionally connected to it that shares its original color, to color. If the starting pixel's color already equals color, return the image unchanged.

Example:

Input: image = [[1,1,1],[1,1,0],[1,0,1]], sr = 1, sc = 1, color = 2
Output: [[2,2,2],[2,2,0],[2,0,1]]