Skip to content

Practice Flood Fill

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#733
LeetCode Problem

Flood Fill

Problem Statement

Starting at image[sr][sc], recolor that pixel and every pixel connected to it through horizontal or vertical neighbors that had the same original color. Use the supplied color for all affected pixels; do not cross pixels of a different original color. Return the modified image.

Source: Flood Fill on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

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]]

# Example 2

Input
image = [[0,0,0],[0,0,0]], sr = 0, sc = 0, color = 0
Output
[[0,0,0],[0,0,0]]

Constraints

m == image.length
n == image[i].length
1 <= m, n <= 50
0 <= image[i][j], color < 2^16
0 <= sr < m
0 <= sc < n

Related LeetCode Problems

Practice more problems similar to Flood Fill.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.