Rotting Oranges
CodingPhone ScreenSoftware EngineerReported Feb, 2026
Examples
Example 1:
Input: grid = [[2,1,1],[1,1,0],[0,1,1]]
Output: 4
Example 2:
Input: grid = [[2,1,1],[0,1,1],[1,0,1]]
Output: -1
Example 1:
Input: grid = [[2,1,1],[1,1,0],[0,1,1]]
Output: 4
Example 2:
Input: grid = [[2,1,1],[0,1,1],[1,0,1]]
Output: -1
You are given an m x n grid where 0 is empty, 1 is a fresh orange, and 2 is a rotten orange.
Every minute, any fresh orange adjacent in the four cardinal directions to a rotten orange also becomes rotten. Return the minimum number of minutes needed to rot all oranges, or -1 if that is impossible.
1 <= grid.length, grid[i].length <= 10grid[i][j] is 0, 1, or 2.Reported as LeetCode 994 in a software engineer phone screen.