← All questions
Coding
Count Sub Islands
Asked at
Freshwoks
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
- 01Traverse every land component in grid2.
- 02DFS or BFS its four-directional cells.
- 03Mark invalid if any visited cell is water in grid1.
- 04Always finish visiting the component.
- 05Increment only if the final flag remains valid.
Reference answer
Then expect these follow-ups
How would you avoid recursion-depth risk?
Tests: follow-up reasoning
What changes if grid2 may be mutated?
Tests: constraint adaptation
Free to read · better with Enzo
Practice this out loud with Enzo
Enzo runs it as a mock interview, pushes back with follow-ups, and grades you on the rubric.
Next question