LearnPy Hub
← Arena
AdvancedRating 1500

Rotting Oranges

In a grid, 2 is a rotten orange, 1 fresh, 0 empty. Each minute rotten oranges spoil fresh neighbours (up/down/left/right). Print the minutes until none are fresh, or -1.

Input

r c, then r lines.

Output

A number.

Sample 1

Input
3 3
2 1 1
1 1 0
0 1 1
Output
4

Sample 2

Input
3 3
2 1 1
0 1 1
1 0 1
Output
-1
solution.py
Output appears here
Rotting Oranges · Python Arena problem · LearnPy Hub