Sheba's Amoebas ⧉
The description states that no two amoebas will overlap. It also states that a black pixel will always have two of its eight neighbours as black pixels. Using this information, we can count the amoebas by "tracing" their outlines using a variation on the Flood fill algorithm, which amounts to a depth-first or breadth-first search with extra steps.
We iterate over each pixel in the input, calling our flood fill on any black pixel that hasn't been searched from. Each amoeba will require one flood fill, so we just count our calls to the algorithm and print the amount.
The C++ shows a recursive flood fill. The Python shows an iterative flood fill.
If you found this solution helpful, consider leaving a star!