Loading...
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
- senior, staff
Problem
Write a function that takes a 2D grid where 0 is empty, 1 is a fresh orange, and 2 is a rotten orange. Each minute, rotten oranges infect all adjacent fresh oranges in 4 directions. Return the minimum minutes until all oranges are rotten, or -1 if impossible.
Practice This Problem
Solve this Python problem with real code execution. DataDriven runs your Python code in a sandboxed Docker environment and grades it instantly.