Surrounded Regions
Mutate a board by replacing every O component not connected orthogonally to a boundary O with X. Boundary-connected regions remain O. Return nothing.
Example 1
0,0X
0,1X
0,2X
0,3X
1,0X
1,1O
1,2O
1,3X
2,0X
2,1X
2,2O
2,3X
3,0X
3,1O
3,2X
3,3X
board = [["X","X","X","X"],["X","O","O","X"],["X","X","O","X"],["X","O","X","X"]][["X","X","X","X"],["X","X","X","X"],["X","X","X","X"],["X","O","X","X"]]Explanation
The enclosed interior three-cell O region becomes X; the bottom-boundary O survives.
Example 2
0,0O
0,1O
1,0O
1,1O
board = [["O","O"],["O","O"]][["O","O"],["O","O"]]Explanation
Every cell touches a boundary on this 2-by-2 board, so no O is captured.
Example 3
0,0X
board = [["X"]][["X"]]Explanation
There is no O region to change.
Constraints
- 1 <= rows, columns <= 200
- Cells are O or X
Function contract
solveArguments: jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 34 cases, on your device.
[["X","X","X","X"],["X","O","O","X"],["X","X","O","X"],["X","O","X","X"]]