Number of Closed Islands — Boundary DFS + Interior Count
Count land islands fully surrounded by water (no border touch). Flood-fill border land first to eliminate open islands, then count remaining closed components.
1582 articles
Count land islands fully surrounded by water (no border touch). Flood-fill border land first to eliminate open islands, then count remaining closed components.
Find the minimum number of 0s to flip to connect two islands. Use DFS to color the first island, then multi-source BFS to expand outward until hitting the second island.
Find the path from top-left to bottom-right that minimizes the maximum absolute difference between consecutive cells. Dijkstra treats effort as edge weight; binary search + BFS checks feasibility for each candidate effort.
Process land additions one at a time and report the island count after each. Union-Find makes each query nearly O(1) amortized — the canonical online connectivity interview problem.
Master Clone Graph (LeetCode 133): a FAANG favorite that tests BFS, DFS, graph traversal, hash map state, and cycle handling. We trace it step by step, derive the optimal pattern, and fortify you against the classic mistakes interviewers love to spot.