Search⌘ K

DIY: Flood Fill

Understand and implement the flood fill algorithm to modify pixel colors in a 2D image array. You'll explore how to identify and update connected pixels sharing the same color starting from a specific coordinate, mastering a fundamental technique applied in many coding interviews.

Problem statement

An image is represented by a 2-D array of integers, each integer represents a pixel value of the image between 0 and 65535.

Given a coordinate (sr, sc) representing the flood fill’s starting pixel (row and column) and a pixel value new_color, flood fill ...