Data Structures & AlgorithmsHardProduct Company SDE · Amazon OA
Problem: A grid holds oranges: 2 = rotten, 1 = fresh, 0 = empty: [[2,1,1],[1,1,0],[0,1,1]]. Each minute every fresh orange adjacent (4-directionally) to a rotten one becomes rotten. What is the minimum number of minutes until no fresh orange remains, or −1 if impossible? Report the number of minutes (the answer is non-negative here).
- A. 5
- B. 4
- C. 3
- D. 6
Correct answer: B. 4
Multi-source BFS from all rotten oranges at time 0 gives the time each fresh orange rots. Running one source at a time gives the wrong total.
More Coding Interview Problems questions
- Problem: Courses 0–5 have prerequisites: 1 needs 0, 2 needs 1, 3 needs 2, 4 needs 5, 5 needs 4. A course can be taken only after all its…
- Problem: Buses run fixed routes; from a stop, the number of distinct routes is what matters. Given the four routes [1,2,7], [3,6,7]…
- Problem: In the array [3, 1, 4, 1, 5, 9, 2, 6] an element is visible from the left if it is strictly greater than every element before it…
- Problem: Find the area of the largest rectangle in a histogram with bar heights [2, 1, 5, 6, 2, 3] (each bar has width 1).
- Problem: Remove exactly 3 digits from the number "1432219" to make the smallest possible number (leading zeros are not allowed in the…
- Problem: How many trailing zeros does 1000! have in base 10?