Island Count (Grids)

A map is a grid of 1 (land) and 0 (water). Land cells that touch up, down, left or right belong to the same island. Print how many islands there are.

Input: r c (1 to 30 each), then r lines of c values, each 0 or 1.

Output: One integer.

Difficulty: Medium. Write your answer in the browser editor, run the examples, then submit it against hidden tests. Python and JavaScript are free; other languages are part of licode Club.

Hint

  • Scan every cell; each unvisited land cell starts a new island.

More Grids practice