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 .