Amazon interview question

Rotten Oranges on the leetcode