Amazon Interview Question

it was a standard rotten oranges question from leetcode