backtracking

2 articles

Cover illustration for Flood Fill Algorithm

Flood Fill Algorithm

The flood fill problem is a way to fill a region of connected pixels with a new colour, starting from a given pixel in an image. You are given an image represented by an m x n grid of integers, where the image[i] represents the pixel value at position (i, j). You are also given the coordinates of a starting pixel (x, y) and a new colour to use for the flood fill operation.

Cover illustration for Generating all K-combinations

Generating all K-combinations

Given two numbers, n and K, write a program to find all possible combinations of K numbers from 1 to n. You may return the answer in any order. Note: This is an excellent problem for learning problem-solving using the inclusion and exclusion principle of combinatorics and backtracking. We can apply similar ideas to solve other problems.