This problem was asked by Linkedin.
Given a 2-dimensional grid consisting of 1's (land blocks) and 0's (water blocks), count the number of islands present in the grid.
The definition of an island is as follows:
- Must be surrounded by water blocks.
- Consists of land blocks (1's) connected to adjacent land blocks (either vertically or horizontally).
Assume all edges outside of the grid are water.
Input:
10001
11000
10110
00000
Output: 3