Problem
Ask
Submissions

Problem: Rotting Oranges

Medium
30 min
Explore how to solve the rotting oranges problem by calculating the minimum time for all fresh oranges to become rotten. Understand grid traversal techniques and how to implement efficient algorithms that run in O(m x n) time for this classic coding challenge.

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 calculating the minimum time for all fresh oranges to become rotten. Understand grid traversal techniques and how to implement efficient algorithms that run in O(m x n) time for this classic coding challenge.

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.