← Graph Exploration

Micro-Drill #145 — Surrounded regions border DFS

Graph Exploration Target: 10s

Start DFS from border O's to mark safe cells. Everything else gets captured.

for i in range(R):
    for j in range(C):
        if (i in (0, R-1) or j in (0, C-1)) and board[i][j] == 'O':
            dfs(i, j)  # mark border O as safe

Type it from memory. Go.

Practice Problems

Related Coding Drills

← Micro #144 Micro #146 →