Remix.run Logo
▲ fatlotus 6 hours ago

Another option if you find yourself with this problem (flood fill, no recursion) is union find/connected components. Like the algorithm proposed in the article, you still need to store O(N) things, and runtime is still O(N).

▲kragen an hour ago | parent [-]

Runtime of union find is slightly worse than O(N). https://www2.eecs.berkeley.edu/Pubs/TechRpts/1974/28764.html