Number of Islands
Given an m x n 2D binary grid which represents a map of '1' (land) and '0' (water), return the number of islands.
An island is surrounded by water and is formed by connecting adjacent land cells horizontally or vertically. You may assume all four edges of the grid are surrounded by water.
The grid is given as an array of equal length strings, so every row is indexed like grid[r][c].
Examples
Input: ["11110","11010","11000","00000"]
Output: 1
Input: ["11000","11000","00100","00011"]
Output: 3
Hints
Every unvisited land cell starts a new island, so scan the grid and flood fill from each one.
Mark land as water while you traverse it so a cell is never counted twice.
Explore only the four cardinal neighbors, and prefer an explicit stack or queue when the grid can be 300 x 300.
Number of Islands
Given an `m x n` 2D binary grid which represents a map of `'1'` (land) and `'0'` (water), return the number of islands.