

{{X, X, O, X, X, X},
{X, X, O, X, O, X},
{X, X, X, O, O, X},
{X, O, X, X, X, X},
{O, X, O, O, X, X},
{X, X, X, X, O, X}}
In the above example, elements at positions (0, 2) and (1,2) do not form an island as there is no 'X' surronding it from the top.
The first line contains two integers 'N', 'M' representing the total number of rows and columns respectively.
Each of the next 'N' lines contains 'M' space-separated characters describing rows of the grid 'G' (each element of G is either 'O' or 'X').
Print 'N' lines each contain 'M' space-separated characters describing the rows of replaced grid 'G'.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= 'N', 'M' <= 1000
Time Limit: 1 sec
This problem is similar to the Flood fill Algorithm,