LearnPy Hub
← Arena
IntermediateRating 1400

Capture Surrounded Regions

Every group of O cells (connected up, down, left, right) that does not touch the edge of the grid is captured: turn it into X. Print the grid.

Input

r and c, then r rows of X and O.

Output

r rows.

Sample 1

Input
4 4
XXXX
XOOX
XXOX
XOXX
Output
XXXX
XXXX
XXXX
XOXX

Sample 2

Input
1 1
O
Output
O
solution.py
Output appears here
Capture Surrounded Regions · Python Arena problem · LearnPy Hub