Search⌘ K

DIY: Flood Fill

Explore the flood fill algorithm to understand how to change connected pixels of the same color in a 2D image array. Learn to implement the floodFill function in JavaScript to update pixel colors starting from a given coordinate. This lesson prepares you to solve problems involving image processing and network-like connectivity using efficient traversal methods.

We'll cover the following...

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 newColor, flood fill ...