dsa2 min read
Surrounded Regions — Boundary DFS
Capture all 'O' regions not connected to the border. Classic boundary DFS: mark safe cells from edges, then flip remaining O to X.
Read →
webcoderspeed.com
3 articles
Capture all 'O' regions not connected to the border. Classic boundary DFS: mark safe cells from edges, then flip remaining O to X.
Count land cells that cannot reach the border. Boundary DFS marks all reachable land from borders, then count remaining land cells.
Count islands fully surrounded by water (no border touch). Flood-fill border land first, then count remaining connected land components.