← 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
Hiring now
Freshwoks has 111 open roles right now
landed applies to roles like these for you, on each company’s own site, with answers written for the role.
Get 5x interviews10 free auto-applies. No card.
Head of Solution Engineering, Americas
San Mateo, CA, United States
Lead - Solution Engineer
Remote
Senior Manager - Sales (Expansion) (m/f/d)
Berlin, Germany
Next question