Amazon interview question

it was a standard rotten oranges question from leetcode