Problems / Rotting Oranges
Medium

Rotting Oranges

Medium 97 submissions 25 coins +100 XP
Graph Matrix
Problem Description
In the grid, `0` is empty, `1` is a fresh orange and `2` is a rotten one. Every minute, fresh oranges next to a rotten one (up/down/left/right) become rotten. Return the minutes until no fresh orange remains, or `-1` if that never happens. **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 3:** ``` Input: grid = [[0, 2]] Output: 0 ```
Constraints
- `1 <= rows, cols <= 10`

Need help?

Connect with expert programmers for real-time collaborative coding, video meetings, and whiteboard sessions via CodeConnect.

Video Call Whiteboard Live Coding Screen Share