Number of Islands
Given a grid of '1' and '0', return the number of islands.
Examples
Input: ["11110","11010","11000","00000"]
Output: 1
Input: ["11000","11000","00100","00011"]
Output: 3
Hints
Consider using a Disjoint Set Union (DSU) data structure to efficiently group connected land cells and count the number of unique sets.
Optimize the BFS/DFS approach by using an iterative method (stack for DFS or queue for BFS) to avoid recursion stack overflow for very large grids.
Extend the solution to handle edge cases like empty grids, grids with no land cells, or grids where all cells are land, ensuring robustness.
Related Problems
Number of Islands
Given a grid of '1' and '0', return the number of islands.