33. Rotten Oranges | Code
Medium

Problem Statement

Implement the multi-source BFS algorithm. Return the minimum number of minutes that must elapse until no cell has a fresh orange. If impossible, return -1.

Examples

1Example 1
Input:
{ "grid": [ [ 2, 1, 1 ], [ 1, 1, 0 ], [ 0, 1, 1 ] ] }
Output:
4
2Example 2
Input:
{ "grid": [ [ 2, 1, 1 ], [ 0, 1, 1 ], [ 1, 0, 1 ] ] }
Output:
-1
3Example 3
Input:
{ "grid": [ [ 0, 2 ] ] }
Output:
0
Loading...

Sign in to Run Code and Submit