Amazon Interview Question

Rotting oranges problem on leetcode. Problem 994