A region is captured by flipping all ‘O’s into ‘X’s in that surrounded region.
The solution here is very simple. First we check if any of the edges of row and column is ‘o’ and also check if their neighbour is also ‘o’ then replace them with the character “1”.
Then we convert all the remaining ‘o’ to ‘x’ and replace ‘1’ with ‘o’. We get our solution.
The steps can be pictorially shown as below: X X X X X X X X X X X X X O O X ---> X O O X -then-> X X X X X X O X X X O X X X X X X O X X X 1 X X X O X X