Count connected groups of '1's in a 2D grid using BFS/DFS or union-find.
Constraints
Example
>>> grid = [ ... ['1','1','0','0','0'], ... ['1','1','0','0','0'], ... ['0','0','1','0','0'], ... ['0','0','0','1','1'] ... ] >>> num_islands(grid) 3 >>> num_islands([['0']]) 0 >>> num_islands([['1']]) 1
Recent Submissions
No submissions yet — hit Run Tests to try!
Hints