Login

Top Apple Coding Interview Questions

Problem title

Difficulty

Avg time to solve

Break Number

Moderate

35 mins

Longest Consecutive Sequence

Moderate

40 mins

Word Break-1

Moderate

36 mins

Implement Trie

Hard

41 mins

Find Number Of Islands

Moderate

34 mins

Excel Column Number

Easy

23 mins

Intersection of Linked List

Easy

25 mins

Search In Rotated Sorted Array

Moderate

30 mins

Rotting Oranges

Moderate

20 mins

Reverse Words In A String

Easy

10 mins

Problem

Submissions

13

Avg. time to solve

20 min

Success Rate

78%

Problem Statement

```
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
```

```
3 3
2 1 1
1 1 0
0 1 1
```

```
4
```

```
Minimum 4 seconds are required to rot all the oranges in the grid as shown below.
```

```
3 3
2 1 0
0 1 1
1 0 1
```

```
-1
```

```
The bottom left corner fresh orange (row 2, column 0) has no adjacent oranges. Hence, it's impossible to rot it.
```

Console

Sample Test Case

Custom Test Case

Download Test Cases

Test Case 1

Test Case 2

Test Case 3

Saving Code...

Full Screen Mode

Change Language

Change Theme

Solution submission not allowed

Save Code

Reset Code