PythiloLesson 25 of 32 · progress kept in this browser

Count islands on a grid

A grid is a graph in disguise: each cell is a node and its up, down, left and right neighbours are edges. Counting islands of land is counting connected components of land cells.

grid = ["LL.",
        ".L.",
        "..L"]
# two islands: diagonal cells do not touch
Your task

Write count_islands(grid), where grid is a list of equal-length strings with "L" for land and "." for water. Neighbours touch up, down, left or right.