DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
medium
Graph

Rotting Oranges

**Problem Statement:** Given the required input arguments, write an efficient algorithm to solve the **Rotting Oranges** problem. Implement the required logic as specified by standard definitions for this classic algorithmic challenge. **Hint / Expected Approach:** Multi-source BFS; track fresh count **Edge Cases to Consider:** - (1) No fresh oranges - (2) No rotten oranges (return 0 if none fresh else -1) - (3) Isolated fresh orange

Examples

Example 1
Input: [[2,1,1],[1,1,0],[0,1,1]]
Output: 4
Explanation: Classic
Example 2
Input: [[2,1,1],[0,1,1],[1,0,1]]
Output: -1
Explanation: Isolated fresh orange
Example 3
Input: [[0,2]]
Output: 0
Explanation: No fresh oranges

Constraints

  • ▪2 <= vertices <= 1000
  • ▪0 <= edges <= 5000
  • ▪Avoid infinite cycles during depth traversal

Watch Out For Edge Cases

  • ▪No fresh oranges
  • ▪No rotten oranges (return 0 if none fresh else -1)
  • ▪Isolated fresh orange
Frequently Asked At
AmazonGoogleMicrosoftAdobeZomato