Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Rotting Oranges
Bookmark
Input
Example 1
Example 2 (impossible)
Single row
Multi-source BFS
Custom
grid
=
[[2,1,1],[1,1,0],[0,1,1]]
minute
0
fresh
6
2
1
1
1
1
1
1
queue
multi-source BFS: rot spreads to neighbors each minute
minute
0
fresh
6
2
1
1
1
1
1
1
queue
multi-source BFS: rot spreads to neighbors each minute
minute
0
fresh
6
1
1
1
1
1
1
2
0
queue
(1,0)
is fresh - rot it
minute
1
fresh
4
2
1
1
2
1
1
1
1
2
0
queue
1,0
0,1
front
(0,-1)
is off the grid - skip
minute
2
fresh
3
2
0
2
1
1
1
1
2
1
2
queue
0,1
1,1
front
(1,1)
rots at minute 2
minute
2
fresh
3
2
0
1
2
1
2
2
1
1
2
1
queue
1,1
front
(0,2)
is fresh - rot it
minute
3
fresh
1
2
0
2
1
2
2
2
1
1
2
2
2
queue
0,2
2,1
front
(2,1)
rots at minute 3
minute
3
fresh
1
2
0
2
1
2
1
2
2
2
3
1
2
2
queue
2,1
front
(1,2)
is empty or already rotten - skip
minute
3
fresh
1
2
0
2
1
2
2
2
1
2
2
1
2
3
queue
(3,1)
is off the grid - skip
minute
4
fresh
0
2
0
2
1
2
2
2
1
2
2
2
3
2
4
queue
(2,2)
spreads rot to its 4 neighbors
minute
4
fresh
0
2
0
2
1
2
2
2
1
2
2
2
3
2
4
queue
return 4
algo
master
.
io
Step:
Spread rot outward from every initially rotten orange
0 / 45
Input
Example 1
Example 2 (impossible)
Single row
Multi-source BFS
Custom
grid
=
[[2,1,1],[1,1,0],[0,1,1]]
0 / 45
algo
master
.
io
Step:
Spread rot outward from every initially rotten orange