Dashboard
LC #130

Surrounded Regions

Pattern · ?

Problem

Capture all regions of 'O' surrounded by 'X'. A region is captured by flipping all 'O's into 'X's.

Constraints

  • 1 ≤ m, n ≤ 200
  • board[i][j] is 'X' or 'O'.

Example

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"]]
Why
The bottom 'O' is on the boundary, so it is not captured. The inner 'O's are captured.

Spot the pattern

Which pattern cracks it?

Hints

One at a time
Solve on LeetCode ↗