Problem
Ask
Submissions

Problem: Rotting Oranges

Medium
30 min
Explore how to solve the Rotting Oranges problem by applying efficient algorithms to track orange decay over a grid. Understand problem constraints, practice coding solutions in a hands-on environment, and improve your ability to analyze time and space complexity in such challenges.

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 01, or 2.

Problem
Ask
Submissions

Problem: Rotting Oranges

Medium
30 min
Explore how to solve the Rotting Oranges problem by applying efficient algorithms to track orange decay over a grid. Understand problem constraints, practice coding solutions in a hands-on environment, and improve your ability to analyze time and space complexity in such challenges.

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 01, or 2.