GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

There is a matrix which can have 3 values 0,1,2.0 ->blocked cell,2 ->virus on the cell,1 -> effected by the virus

There is a  matrix which can have 3 values 0,1,2 . 0 represents blocked cell , 2 represents virus on the cell , 1 represents a cell which can be effected by the virus . Neighbouring cell's having value 1 infected by the virus and converts into 2 .After this recently converted cell's will infect all  the cells having value as 1 and changed into 2 . This process will go on until we have reach a situation such that no further conversion can took place. 

We are considering all the  8 neighbours . Eg - if the cell in the consideration is i,j then the neighbours will be (i , j-1)  , (i-1 , j-1) , (i-1 , j) , (i-1 , j+1) , (i , j+1) , (i+1 , j+1) , (i+1 , j) , (i+1 , j-1) .

So, we need to find out the number of chances it will take to convert the matrix to the above mentioned location .

It would be more good if we can print all the intermediate state .

asked Oct 14, 2015 by codersx

1 Answer

Your question is almost the same as this one : http://qa.geeksforgeeks.org/1220/microsoft-interview-question?show=1220#q1220
check it out, you can print intermediate states as well.

answered Oct 14, 2015 by Swanky
...