DSA interview question
A satellite map is a grid of '1' (land) and '0' (water). An island is a group of land cells connected horizontally or vertically (diagonals don't count), and the edge of the map counts as water. Count the islands. Scan every cell, and when you hit land that hasn't been visited, that's a new island: flood-fill it with BFS or DFS over the four neighbours so its other cells aren't counted again.
Example: 11000 / 11000 / 00100 / 00011 → 3.
int numIslands(vector<string> grid);
| Input (rows) | Output | Explanation |
|---|---|---|
11110 11010 11000 00000 | 1 | |
11000 11000 00100 00011 | 3 | |
101 010 101 | 5 | Diagonals don't connect with 4 directions |
1 | 1 | |
0 | 0 |
(Confirm: connectivity is 4-directional only; the grid may be modified.)
On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.
Book a free mock interviewAll 474 dsa interview questions
DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in