Problem
Capture every surrounded region of letter 'O' cells in a rectangular board of 'X' and 'O'. Cells connect horizontally or vertically, not diagonally. A region is surrounded exactly when none of its cells touches the board's outer edge. Change all cells in such regions to 'X', leaving other cells unchanged.
void solve(vector<vector<char>>& board);
Mutate the original character matrix; return nothing. Quoted rows below are shorthand for character rows.
Examples
Input rows: ["XXXXX","XOOXX","XXOXX","OXXOX","XXXXX"]
Rows after call: ["XXXXX","XXXXX","XXXXX","OXXXX","XXXXX"]
The left-edge O survives; the other O regions have no edge connection.
Input rows: ["OOO"]
Rows after call: ["OOO"]
Constraints
-
Both row and column counts are between 1 and 200.
-
Every original cell is
'X'
or
'O'
.