dsa1 min read
Number of Enclaves — Boundary DFS Count
Count land cells that cannot reach the border. Boundary DFS marks all reachable land from borders, then count remaining land cells.
Read →
1575 articles
Count land cells that cannot reach the border. Boundary DFS marks all reachable land from borders, then count remaining land cells.
Count islands in grid2 that are subsets of islands in grid1. DFS the island in grid2 and verify every cell is also land in grid1.
Find the largest island after flipping exactly one 0 to 1. Color each island with DFS, store sizes, then check each 0 cell's unique neighbour islands.
Find cells that can flow to both Pacific and Atlantic oceans. Run DFS backwards from each ocean border, find intersection.
Find shortest clear path from top-left to bottom-right in binary matrix using 8-directional BFS. Return path length or -1.