Problem
You get a grid grid with m rows and n columns. Each cell holds one of three values: 0 for an empty cell, 1 for a fresh orange, or 2 for a rotten orange.
Each minute, every fresh orange next to a rotten orange becomes rotten. Two cells are next to each other when one is directly above, below, left or right of the other.
Return the smallest number of minutes until no fresh orange is left. If a fresh orange can never become rotten, return -1.
Example 1
- Input:
- grid = [[1,1,0],[2,1,1],[0,1,2]]
- Output:
- 2
- Explanation:
- The two rotten oranges spread at the same time. After minute 1, only the orange in the top row, middle column is still fresh. It becomes rotten in minute 2.
Example 2
- Input:
- grid = [[2,0,1]]
- Output:
- -1
- Explanation:
- The empty cell separates the fresh orange from the rotten orange.
Example 3
- Input:
- grid = [[0,2]]
- Output:
- 0
- Explanation:
- No fresh orange is in the grid at the start.
Constraints
- m == grid.length
- n == grid[i].length
- 1 <= m, n <= 10
- grid[i][j] is 0, 1 or 2
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Contain Virus
Coding · Array · Breadth-First Search · Depth-First Search
- Escape the Spreading Fire
Coding · Array · Binary Search · Breadth-First Search
- Find the Safest Path in a Grid
Coding · Array · Binary Search · Breadth-First Search
- Making A Large Island
Coding · Array · Breadth-First Search · Depth-First Search
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 4 records
Amazon
Leetcode 994. Rotting Oranges
Reported Aug 1, 2026 · 4 source reports
JUNIOR, SENIOR
Source snapshot: Nov 12, 2026
View sourceAnduril
Leetcode 994. Rotting Oranges
Reported Aug 5, 2026 · 1 source report
STAFF
Source snapshot: Nov 12, 2026
View sourceOpenAI
Leetcode 994. Rotting Oranges
Reported Jun 1, 2026 · 2 source reports
SENIOR
Source snapshot: Nov 12, 2026
View sourceRoblox
Leetcode 994. Rotting Oranges
Reported May 24, 2026 · 1 source report
SENIOR
Source snapshot: Nov 12, 2026
View source