CodeOath
← All problems

Rotting Oranges

Medium
graphsbfsmatrix

You're given a grid where each cell is 0 (empty), 1 (fresh orange), or 2 (rotten orange). Every minute, any fresh orange 4-directionally adjacent to a rotten orange becomes rotten.

Return the number of minutes until no cell has a fresh orange, or -1 if that's impossible.

Example:

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