Amazon interview question

Rotting oranges problem on leetcode. Problem 994