← Practice · BFS / DFS
Rotting Oranges Medium
A grid has cells 0 (empty), 1 (fresh orange) and 2 (rotten orange). Each minute, every fresh orange that is directly up, down, left or right of a rotten orange becomes rotten. Return the minimum number of minutes until no fresh orange remains, or -1 if that is impossible.
Examples
[[2,1,1],[1,1,0],[0,1,1]] -> 4[[0,2]] -> 0
Define a function named orangesRotting in JavaScript.
00:00
JavaScript · Tab indents · Ctrl/⌘+Enter runs the tests