← All problems
Number of Islands
Count the islands (connected '1's, 4-directional) in a binary grid.
Complexity
Time O(mn), Space O(mn) worst-case recursion
Common pitfalls
- 8-directional by mistake
- Not marking visited (infinite loop)
Your solution
Log in to save your code and track progress.