Approach hintTry it first, then revealHide
Regions that touch the border can never be captured. Mark every O reachable from a border cell with DFS or BFS, then flip the unmarked O cells to X and restore the marked ones.
Regions that touch the border can never be captured. Mark every O reachable from a border cell with DFS or BFS, then flip the unmarked O cells to X and restore the marked ones.