Problem of the day
Input:
3 3
XXX
XOX
XXX
Output:
XXX
XXX
XXX
Explanation:
The ‘O’ is surrounded by ‘X’s in all directions, so it is captured and flipped.
The first line of the input contains an integer, ‘T’, denoting the number of test cases.
The First line of each test case contains two integers, ‘N’ and ‘M’ denoting the number of rows and columns in the ‘GRID’.
The next ‘N’ lines of each test case contain ‘M’ characters, ‘O’ or ‘X’.
Modify the original ‘GRID’ by flipping the captured ‘O’s.
1 <= T <= 10
1 <= N,M <= 200
Time Limit: 1 sec
2
3 3
XXX
XOX
XXX
3 4
XXXO
XXOX
XOXX
XXX
XXX
XXX
XXXO
XXXX
XOXX
Test 1:
The ‘O’ is surrounded by ‘X’s in all directions, so it is captured and flipped.
Test 2:
The ‘O’ in the first row is only surrounded by 2 sides.
The ‘O’ in the second row is surrounded by all 4 sides, hence
flipped.
The ‘O’ in the third row is only surrounded by 3 sides.
2
3 3
XXX
XOX
XOX
3 4
OOXO
OXOX
OOXO
XXX
XOX
XOX
OOXO
OXXX
OOXO