Skip to main content

Practice ยท 2 of 2

Connected components (flood fill)

Implement int count_islands(const std::vector<std::string>& grid) where '1' is land and '0' is water; an island is a maximal group of '1's connected horizontally or vertically. Sink each island as you find it (mutate the grid copy or use a visited matrix) and count the discoveries. This is DFS/BFS on a grid.

Difficulty: intermediate

Back to lesson: Practice: Structure practice