LeetCode 200 Number of Islands - Problem Statement

The problem

Given an m × n 2D grid of '1's (land) and '0's (water), count the number of islands.

An island is surrounded by water and formed by connecting adjacent lands horizontally or vertically.

With this grid:

1 1 0 0 0
1 1 0 0 0
0 0 1 0 0
0 0 0 1 1

There are 3 islands: top-left 2×2 block, middle single cell, bottom-right 2 cells.

Constraints: 1m,n3001 \le m, n \le 300.