Compute fruit spoilage time in a grid | Amazon Interview Question