Number of Islands
A medium-tier problem at 62% community acceptance, tagged with Array, Depth-First Search, Breadth-First Search. Reported in interviews at Anduril and 85 others.
Number of Islands shows up across 86 companies, from Intel and Rivian to smaller shops like EarnIn and Whatnot. It's a medium-difficulty grid traversal problem that looks simple on the surface: count connected regions of land in a 2D matrix. But the real test is picking the right traversal method under time pressure. If you freeze on whether to use DFS, BFS, or Union Find during your live assessment, StealthCoder runs invisibly and surfaces a working solution in seconds. It's the kind of problem you either nail or sink on.
Companies that ask "Number of Islands"
Number of Islands is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage.
Get StealthCoderThe trick is recognizing this as a connected-components problem. You iterate through the grid, and whenever you hit an unvisited land cell, you increment the island count and mark all connected land cells as visited in one pass. Most candidates default to DFS recursion, which works but can hit stack limits on huge grids. BFS avoids that. Union Find is overkill here but still valid. The gotcha: forgetting to mark visited cells, or mixing up your adjacency logic (4-directional vs 8-directional). On a live OA, if the pattern doesn't click immediately, StealthCoder gives you the DFS template and you move on.
Pattern tags
You know the problem.
Make sure you actually pass it.
Number of Islands recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Number of Islands interview FAQ
Is Number of Islands still heavily asked at big tech?+
Yes. It appears in interview reports from Intel, Rivian, HPE, and at least 80+ other companies. The acceptance rate sits at 62%, so it's accessible but not trivial. It's not going anywhere.
What's the actual algorithmic pattern here?+
Connected-components counting on a grid. Mark a starting land cell and recursively or iteratively mark all adjacent land cells. Each component you discover and clear is one island. The method (DFS, BFS, UF) is a choice; the pattern is always the same.
When does the 'obvious' approach fail?+
If you don't track visited cells, you'll count the same island multiple times. If you use deep recursion on a large grid, you'll hit stack overflow. BFS or iterative DFS sidesteps this. Union Find is slower on this problem but guarantees no recursion depth issues.
How does this relate to the other matrix topics?+
Number of Islands is the canonical example of applying DFS or BFS to a matrix. It's also a textbook Union Find use case. Mastering this problem teaches you pattern recognition for Surrounded Regions, Walls and Gates, and similar grid-based connectivity problems.
What's the most common mistake in interviews?+
Forgetting to mark cells as visited before recursing, leading to infinite loops or wrong counts. The second is assuming 8-directional adjacency when the problem specifies 4-directional. Read the problem statement carefully and test with a small example first.
Want the actual problem statement? View "Number of Islands" on LeetCode →