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
Press Submit to check your solution.
Back to lesson: Practice: Structure practice