dsa · medium
Number of Islands
GreyOrangeGraphBFS/DFS
Given an m x n 2D binary grid which represents a map of 1s (land) and 0s (water), return the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. The grid is provided as a list of strings.
Arguments
grid— the 2D grid
**Example 1:** `` Input: ["11000","11000","00100","00011"] Output: 3 ``
Constraints
1 <= m, n <= 300 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: ["11000","11000","00100","00011"] Expected: 3
Example 2
Input: ["111","010","111"] Expected: 1