Amazon interview question

round 2 - Rotten Oranges problem (LeetCode)