Compute fruit spoilage time in a grid
AmazonSoftware Engineer · OnsiteLast updated
This question evaluates a candidate's understanding of graph traversal concepts, grid-based state propagation, and reachability analysis in time-evolving systems.
Given an m×n grid representing kitchen cells: 0 for empty, 1 for fresh fruit, and 2 for spoiled fruit. Each minute, any fresh fruit adjacent (up, down, left, right) to a spoiled fruit becomes spoiled. Return the minimum number of minutes needed to spoil all fresh fruits, or -1 if it is impossible. Describe your algorithm, prove correctness at a high level, and analyze time and space complexity. Implement a function that computes the answer.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.