Answer to Question #309405 in Algorithms for Akash srivastava

Question #309405

Rotten Oranges

Time Limit: 2 sec

Memory Limit: 128000 kB

Problem Statement

Given a matrix of dimension n*m where each cell in the matrix can have values 0, 1 or 2 which has the following meaning:


0: Empty cell

1: Cells have fresh oranges

2: Cells have rotten oranges


So we have to determine what is the minimum time in sec required so that all the oranges become rotten. A rotten orange at index [i,j] can rot other fresh orange at indexes [i-1,j], [i+1,j], [i,j-1], [i,j+1] (up, down, left and right) in 1 sec. If it is impossible to rot every orange then simply print -1.

Input

First line of input has two integers n & m .

Then n lines follows having m space seperated integers which can be 0,1 or 2.



0
Service report
It's been a while since this question is posted here. Still, the answer hasn't been got. Consider converting this question to a fully qualified assignment, and we will try to assist. Please click the link below to proceed: Submit order

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS