LeetCode 733 Flood Fill - Problem Statement

The problem

Given an image (2D grid of pixel colors), a starting pixel, and a new color, perform a flood fill.

Change the starting pixel and all connected pixels of the same color to the new color. Connected means adjacent horizontally or vertically.

With image = [[1,1,1],[1,1,0],[1,0,1]], start (1,1), new color 2:

  • Starting pixel is 1. All connected 1's become 2.
  • Result: [[2,2,2],[2,2,0],[2,0,1]].

The bottom-right 1 isn't connected to the start (blocked by 0's).

Constraints: Image size up to 50×5050 × 50.