Gamified challenge · Breadth-first search
crate[r][c] is one slot of a crate: 0 is an empty slot, 1 is fresh fruit and 2 is rotten fruit. Every minute, each fresh fruit that touches a rotten fruit up, down, left or right turns rotten. Rot can't cross empty slots or go diagonally.
Write minutesToRot(crate) (Python: minutes_to_rot(crate)) that returns the number of minutes until no fresh fruit is left. Return 0 if there is no fresh fruit at the start, and -1 if some fresh fruit can never be reached by rot.
For [[2, 1, 1], [1, 1, 0], [0, 1, 1]] the rot spreads from the top-left corner and the last fruit (bottom-right) goes bad after 4 minutes.
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google