Start dfs from the boundary of matrix from each element which is a 
zero(mark it to Z), and mark all reachable zeroes as D.
Finally traverse the matrix marking all as X except the D's, mark them as O.


eg:



xxxx
xxox
xoxx
xxox

the inner o's would be marked as D's since we can get to the from the o in 
the last line that is at a boundary and thus guarantees an opening.



On Tuesday, June 11, 2013 12:35:30 PM UTC+5:30, Jai Shri Ram wrote:
>
> Given a 2D board containing 'X' and 'O', capture all regions surrounded 
> by 'X'.
>
> A region is captured by flipping all 'O's into 'X's in that surrounded 
> region .
>
> For example,
>
> X X X X
> X O O X
> X X O X
> X O X X
>
> After running your function, the board should be:
>
> X X X X
> X X X X
> X X X X
> X O X X
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Reply via email to