Skip to main content
mediumNeetCode 150

Rotting Oranges

Given a grid where 0=empty, 1=fresh orange, 2=rotten orange Each minute, rotten oranges spread to adjacent fresh oranges (4-directionally) Return the minimum minutes until all oranges are rotten, or -1 if impossible Example: [[2,1,1],[1,1,0],[0,1,1]] => 4

Rot spreads one layer per minute, so I seed the queue with every rotten orange at once. BFS depth is the answer.

Arrays & HashingBFS / DFSGraphs

Meet Coco

Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Typing with Coco is free when you sign in, up to a daily limit. Talking with her out loud comes with the $79 pack. Anyone can open the editor and run their code.

1Minimum Time for All Oranges to Rotmedium
Based onLeetCode