Dashboard
LC #994
Rotting Oranges
Pattern · ?AmazonGoogleMetaBloomberg
Problem
Find how many minutes until all oranges are rotten. Rotten oranges infect adjacent fresh oranges each minute.
Constraints
- 1 ≤ m, n ≤ 10
- grid[i][j] is 0 (empty), 1 (fresh), or 2 (rotten)
- Return -1 if impossible to rot all oranges
Example
- Input
- grid = [[2,1,1],[1,1,0],[0,1,1]]
- Output
- 4
- Why
- Rotten orange at [0,0] spreads: after 4 minutes all fresh oranges are rotten
Spot the pattern
Which pattern cracks it?
Hints
One at a time