Practice Escape the Spreading Fire
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
grid uses 0 for grass, 1 for initial fire, and 2 for impassable walls. Wait at (0,0), then move one side-adjacent grass cell per minute toward the bottom-right safehouse. Fire spreads one cell in all four directions through nonwalls every minute, including each minute of the initial wait. After movement, a cell reached by fire cannot be occupied unless it is the safehouse just reached that minute. Reaching the safehouse just before fire spreads there is allowed. Return the maximum safe initial wait, -1 if escape is impossible, or 10^9 if waiting is unbounded.
Source: Escape the Spreading Fire on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
grid = [[0,2,0,0,0,0,0],[0,0,0,2,2,1,0],[0,2,0,0,1,2,0],[0,0,2,2,2,0,2],[0,0,0,0,0,0,0]]
3
# Example 2
grid = [[0,0,0,0],[0,1,2,0],[0,2,0,0]]
-1
# Example 3
grid = [[0,0,0],[2,2,0],[1,2,0]]
1000000000
Constraints
Related LeetCode Problems
Practice more problems similar to Escape the Spreading Fire.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.