https://leetcode.com/problems/rotting-oranges/?envType=problem-list-v2&envId=7p5x763
You are given an m x n grid where each cell can have one of three values:
0 representing an empty cell,1 representing a fresh orange, or2 representing a rotten orange.Every minute, any fresh orange that is 4-directionally adjacent to a rotten orange becomes rotten.
Return the minimum number of minutes that must elapse until no cell has a fresh orange. If this is impossible, return -1.

For Rotting Oranges, the cleanest solution is multi-source BFS (queue). Every rotten orange (2) is a starting point at time 0. Each minute is one BFS “layer”, and rotting spreads to 4-directional neighbors.
Why BFS is the right tool
What’s going wrong in your rough approach
(r, c). But rotting happens from all rotten oranges at once, not one at a time.while r in range(...) isn’t valid, r-- isn’t Python, if r = 0 should be ==, and boundary checks like r <= len(grid) should be r < len(grid).Correct BFS algorithm
fresh).0.