Imagine you're a cartographer analyzing satellite imagery of an archipelago! You have a 2D grid map where '1' represents land and '0' represents water. Your mission is to count how many separate islands exist in this region.
An island is formed by connecting adjacent land cells ('1's) either horizontally or vertically (diagonal connections don't count). Think of it like walking from one piece of land to another - you can only move up, down, left, or right.
Example: If you see connected land masses, they form a single island. Separate land masses surrounded by water are different islands.
The entire grid is surrounded by water, so any land on the edges is still considered part of an island if connected to other land.
Input & Output
Constraints
- m == grid.length
- n == grid[i].length
- 1 ≤ m, n ≤ 300
- grid[i][j] is '0' or '1'
- Grid cells contain only characters '0' and '1'