Back to course home
0% completed
Solution: Rotting Oranges
Problem Statement
You are given an m x n
matrix in which each cell can have one of three values:
0
representing anempty cell
,1
representing afresh orange
, or2
representing arotten orange
.
At each minute, any fresh orange becomes rotten if it is 4-directionally
adjacent to a rotten orange.
Return the minimum number of minutes
that should be passed until all the orange gets rotten. If it is impossible, return -1.
Examples
- Input: grid =
[[2,1,0,0],
[1,1,1,0],
[0,1,1,1],
[0,0,1,2]]
- Expected Output:
3
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible