New update is available. Click here to update.

Posted: 13 Sep, 2020

Difficulty: Moderate

```
1. The grid has 0-based indexing.
2. A rotten orange can affect the adjacent oranges 4 directionally i.e. Up, Down, Left, Right.
```

```
The first line of input contains two single space-separated integers 'N' and 'M' representing the number of rows and columns of the grid respectively.
The next 'N' lines contain 'M' single space-separated integers each representing the rows of the grid.
```

```
The only line of output contains a single integer i.e. The minimum time after which no cell has a fresh orange.
If it's impossible to rot all oranges, print -1.
```

```
You are not required to print the expected output, it has already been taken care of. Just implement the function.
```

```
1 <= N <= 500
1 <= M <= 500
0 <= grid[i][j] <= 2
Time Limit: 1 sec
```

SIMILAR PROBLEMS

Is Graph Bipartite?

Posted: 28 Jan, 2022

Difficulty: Moderate

Valid Arrangement of Pairs

Posted: 28 Jan, 2022

Difficulty: Hard

Valid Arrangement of Pairs

Posted: 28 Jan, 2022

Difficulty: Hard

Left Right Print

Posted: 9 Jul, 2022

Difficulty: Moderate

The Summit

Posted: 15 Sep, 2022

Difficulty: Easy

Distance to a Cycle in Undirected Graph

Posted: 7 Nov, 2022

Difficulty: Moderate

Popular Interview Problems: