Count Islands on a Map
A map is given as an array of strings grid, where each character is "1" (land) or "0" (water). Land cells that touch horizontally or vertically belong to the same island. Diagonal contact does not connect cells.
Return the number of islands.
Example 1
Input: grid = ["11000","11000","00100","00011"] Output: 3
Example 2
Input: grid = ["101","010","101"] Output: 5 Explanation: Only diagonal contacts, so every land cell is its own island.
Constraints
- 0 <= grid.length <= 300
- 0 <= grid[i].length <= 300
- All rows have the same length.
Hint 1
Scan every cell; when you find unvisited land, you have found a new island.
Hint 2
Flood-fill from that cell (DFS or BFS) and mark all connected land as visited.
Good practice for: Backend Developer, Game Developer, Full Stack Developer, Data Scientist, Machine Learning Engineer
Run checks your code on 3 sample tests. Submit runs all 8 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.