The Infection Spread
A hard Python interview practice problem on DataDriven. Write and execute real python code with instant grading.
- Domain
- Python
- Difficulty
- hard
- Seniority
- L5
Problem
Given a 2D grid where 0 = empty, 1 = fresh orange, 2 = rotten orange, simulate minute-by-minute spread in 4 directions. Each minute, every fresh orange that is 4-directionally adjacent to a rotten orange becomes rotten. Return the minimum number of minutes until no fresh orange remains. Return -1 if some fresh orange can never become rotten. Return 0 if there are no fresh oranges to begin with.
Summary
It starts with one, and then it spreads.
Practice This Problem
Solve this Python problem with real code execution. DataDriven runs your Python code in a real environment and grades it automatically.