Start DFS/BFS from the boundary nodes(Only the boundary nodes). => (i == 0 || j == 0 || i == row || j == col)
- Convert all the nodes reachable to some distinguishable character, like 'S'.
- All the remaining nodes are surrounded nodes.
- Scan the matrix and convert all the 'O' to 'X' and 'S' to 'O'.