Surrounded Regions
Part of Practice: Flood Fill & Regions
You get a grid (up to 200×200) of "X" and "O" cells. A region of connected "O"s (up/down/left/right) is captured — every cell flipped to "X" — unless the region touches the edge of the board. Modify the board in place so all captured regions are flipped and edge-touching regions are left alone.
Examples
- Input:
- board = [["X","X","X","X"],["X","O","O","X"],["X","X","O","X"],["X","O","X","X"]]
- Output:
- [["X","X","X","X"],["X","X","X","X"],["X","X","X","X"],["X","O","X","X"]]
The three connected O's in the middle are fully enclosed by X's, so they flip. The O at (3,1) sits on the bottom edge, so its region survives.
- Input:
- board = [["O","O"],["O","O"]]
- Output:
- [["O","O"],["O","O"]]
Every O touches the border, so nothing is captured.
Hints
One at a time — struggle first, peek second.
Your thinking space — verify on LeetCode, then mark it.