Given a grid where each cell is empty (0), a fresh orange (1), or a rotten orange (2), every minute any fresh orange adjacent to a rotten one becomes rotten. Return the minimum number of minutes until no fresh orange remains, or -1 if that's impossible.
grid = [[2,1,1],[1,1,0],[0,1,1]]4Solve it in the editor. Sign in free to run your Python or JavaScript against test cases, get a verdict, and track your attempts.
Solve on FeatCode →A graph models relationships as nodes and edges, which can be directed or undirected, weighted or not. Most graph problems come down to choosing the right traversal — DFS, BFS, or union-find — for what you're trying to find.
Original problem on LeetCode ↗