
Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
For some tile (x, y), how can we determine when, if ever, the fire will reach it?
We can use multi-source BFS to find the earliest time the fire will reach each cell.
Then, starting with a given t minutes of staying in the initial position, we can check if there is a safe path to the safehouse using the obtained information about the fire.
We can use binary search to efficiently find the maximum t that allows us to reach the safehouse.