dsa · medium

Surrounded Regions

GreyOrangeGraphRecursion

Board of "X" / "O". Capture ("O""X") every region fully surrounded by "X". Border-connected "O"s stay. Return the board.

Arguments

**Example**

`` Input: [["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"]] ``

Constraints

1 <= m, n <= 200 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
[["X","X","X","X"],["X","O","O","X"],["X","X","O","X"],["X","O","X","X"]]

Expected:
[["X","X","X","X"],["X","X","X","X"],["X","X","X","X"],["X","O","X","X"]]

Open in the Dojo editor