Given a 2D grid of '1' and '0', count how many islands it contains. An island is formed by horizontally or vertically adjacent land cells, and water separates different islands.
Constraints
1 <= rows, cols <= 300
grid[i][j] is '0' or '1'
Only 4-directional adjacency counts
Interviewer
Your question is Count Islands in a Grid. Start with the requirements in the Question tab.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.