A stone game is played on a grid board. Every cell holds the text "X" or the text "O".
A region is a group of "O" cells that are joined up, down, left or right. A region is captured when "X" cells close it in on every side. None of its cells is on the border of the board.
Change every "O" of a captured region to "X". A region that has a cell on the border has a way out, so leave it as it is.
Return the board after all captures.
Examples
Example 1:
Input: board = [["O","X","X","O"],["X","O","O","X"],["X","O","O","X"],["O","X","X","X"]]
Output: [["O","X","X","O"],["X","X","X","X"],["X","X","X","X"],["O","X","X","X"]]
Explanation: The four O cells in the middle are closed in by X cells, so they become X. The O cells in the corners are on the border, so they stay.
Example 2:
Input: board = [["X","O","X"],["X","O","X"],["X","X","X"]]
Output: [["X","O","X"],["X","O","X"],["X","X","X"]]
Explanation: The O in the top row is on the border. The O below it is joined to it, so the whole region touches the border. Nothing is captured.
Example 3:
Input: board = [["X","X","X","X"],["X","O","X","O"],["X","O","X","X"],["X","X","O","X"]]
Output: [["X","X","X","X"],["X","X","X","O"],["X","X","X","X"],["X","X","O","X"]]
Explanation: The two joined O cells in column 1 are closed in, so they become X. The O in the last column and the O in the last row touch the border, so they stay.