← All mock interviewsHints used: 0
Number of Islands Mock Interview
- ✓Problem→
- 2Clarifying Questions→
- 3Constraints→
- 4Brute Force→
- 5Complexity Analysis→
- 6Pattern Recognition→
- 7Optimized Solution→
- 8Implementation→
- 9Testing→
- 10Follow-Up→
- 11Evaluation
Problem
Given an m × n grid of characters where '1' represents land and '0' represents water, return the number of islands. An island is a maximal group of land cells connected horizontally or vertically (not diagonally). You may assume the grid is surrounded by water.
Constraints
- 1 ≤ m, n ≤ 300
- grid[i][j] is '0' or '1'
Example
in: grid = [["1","1","0"],["0","1","0"],["0","0","1"]]
out: 2
Clarify
Before choosing anything: what would you ask the interviewer? What assumptions are you making? (Duplicates? Empty input? Value ranges? What to return when there is no answer?)