Exercises/#49 Rotting Oranges (Multi-source BFS)
#49

Rotting Oranges (Multi-source BFS)

MediumπŸ•ΈοΈ Graphs
80 XP

Problem

In a grid, 0=empty, 1=fresh orange, 2=rotten orange. Each minute, rotten oranges spread to adjacent fresh ones. Return minutes until all rot, or -1 if impossible.

Examples

Input: [[2,1,1],[1,1,0],[0,1,1]]
Output: 4

Input: [[2,1,1],[0,1,1],[1,0,1]]
Output: -1
graphbfsmatrixmulti-source
AI Assistantβ€” powered by AI

Unlock hints progressively β€” start gentle, go deeper only if needed.

πŸ’‘

Level 1: Gentle Nudge

A subtle direction

πŸ—ΊοΈ

Level 2: Approach

The algorithm to use

πŸ”

Level 3: Detailed

Step-by-step guidance

49 / 150

Your Solution

⚑ JavaScript

to save progress and use AI features