Tap here to switch tabs
Problem
Submissions

Problem: Rotting Oranges

Rotting Oranges gives a grid of empty cells, fresh oranges, and rotten oranges. Find the minutes until all fresh oranges rot through four-directional contact, or return -1 if any remain.

Statement

Consider an m×nm \times n grid containing cells with three potential values:

  • 00, which indicates an unoccupied cell.

  • 11, representing a freshly picked orange.

  • 22, indicating a rotten orange.

Any fresh orange that is 4–directionally adjacent to a rotten orange will also turn rotten with each passing minute.

Your task is to determine the minimum time required for all cells to have rotten oranges. In case, this objective cannot be achieved, return −1-1.

Constraints:

  • m == grid.length

  • n == grid[i].length

  • 11 ≤\leq m, n ≤\leq 1010

  • grid[i][j] is 0, 1, or 2.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Rotting Oranges

Rotting Oranges gives a grid of empty cells, fresh oranges, and rotten oranges. Find the minutes until all fresh oranges rot through four-directional contact, or return -1 if any remain.

Statement

Consider an m×nm \times n grid containing cells with three potential values:

  • 00, which indicates an unoccupied cell.

  • 11, representing a freshly picked orange.

  • 22, indicating a rotten orange.

Any fresh orange that is 4–directionally adjacent to a rotten orange will also turn rotten with each passing minute.

Your task is to determine the minimum time required for all cells to have rotten oranges. In case, this objective cannot be achieved, return −1-1.

Constraints:

  • m == grid.length

  • n == grid[i].length

  • 11 ≤\leq m, n ≤\leq 1010

  • grid[i][j] is 0, 1, or 2.