Surrounded Regions
Given an m x n matrix board containing 'X' and 'O', capture all regions that are 4-directionally surrounded by 'X'. A region is captured by flipping all 'O's into 'X's in that surrounded region.
Surrounded Regions

Given an m x n matrix board containing 'X' and 'O', capture all regions that are 4-directionally surrounded by 'X'. A region is captured by flipping all 'O's into 'X's in that surrounded region.

Example 1:
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"]]
Input
arr =[["X","X","X","X"],["X","O","O","X"],["X","X","O","X"],["X","O","X","X"]]

X

X

X

X

X

O

O

X

X

X

O

X

X

O

X

X

X (Captured)
O (Region)
T (Safe)
Phase: border

Mark border-connected Os as safe (T)

Variables
VariableValue
m4
n4
DepthFunction Call
Stack empty
0/3