Flood Fill Problem
Flood Fill Problem — ExecCode Hard DSA Practice
Solve the Flood Fill problem on ExecCode. Free online hard DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.
Problem description
An image is represented by an m×n grid of integers. Starting at (sr, sc), replace the color of the connected component (4-directional) that contains the start pixel with the given color. Return the modified image.
Examples
Input image = [[1, 1, 1, 0, 1], [1, 1, 0, 0, 1], [1, 0, 1, 1, 1], [0, 0, 1, 1, 0]], sr = 0, sc = 0, color = 2; Output [2, 2, 2, 0, 1, 2, 2, 0, 0, 1, 2, 0, 1, 1, 1, 0, 0, 1, 1, 0]. Input image = [[0, 0, 0], [0, 0, 0]], sr = 0, sc = 0, color = 0; Output [0, 0, 0, 0, 0, 0]
Constraints
1 ≤ m, n ≤ 50 0 ≤ sr < m, 0 ≤ sc < n 0 ≤ image[i][j], color < 2¹⁶
Practice Flood Fill free on ExecCode. Browse DSA problems, topic map, and placement guides.