Count Islands

Write the code, see it run, pass the checks.

The problem

  • medium
  • Code
  • Pro

Write countIslands(grid): grid is an array of strings of equal length, where "#" is land and "." is water. An island is land joined up, down, left or right (not diagonally). Return how many islands there are. ["##...", "##...", "..#..", "...##"] has 3. The checks include a 300 by 300 grid.

Your code must pass

  • Counts separate islands
  • Joins land up, down, left and right, not diagonally
  • Returns 0 for all water or an empty grid
  • Handles a 300 by 300 grid