← 返回 oracle 的题目列表Number of Islands (LC 200)
类型:qbank
Phone-screen flood-fill: count the distinct islands in a 2D grid of land and water cells using DFS, then state time and space complexity on demand.
Requirements
Given a 2D grid of '1' (land) and '0' (water), count the number of distinct islands.
An island is formed by connecting adjacent land cells horizontally or vertically (4-directional connectivity).
A straightforward DFS or BFS flood-fill that marks visited land is accepted.
Be ready to state time and space complexity precisely — the interviewer asks for both right after the code passes.
Notes
Equivalent to LeetCode 200. Asked as a phone-screen coding problem; the solution is run against test cases on HackerRank and must pass all of them.
Complexity is O(m·n) time and O(m·n) worst-case stack space for recursive DFS. The interviewer probes both immediately after the run goes green.