This question evaluates graph traversal and grid-based pathfinding skills, including connectivity analysis, obstacle handling, and reasoning about time-dependent spreading processes.
You are given a 2D grid representing a grassland.
S
: start
T
: target
.
: free cell
#
: blocked cell (cannot enter)
F
: initial fire source (for Part C)
Given the grid with # blockers (no fire yet), determine whether there exists any path from S to T.
Now suppose one additional free cell is turned into a blocker # (you are given its coordinates). Determine whether S can still reach T after this change.
Now consider fire spread in the grid:
0
, all
F
cells are on fire.
#
.
S
. You may
wait
at
S
for
w
minutes (where
w ≥ 0
is an integer), then start moving 1 cell per minute.
T
is allowed only if you arrive before it burns (state the rule explicitly in your solution, e.g., “arrive strictly before it burns”).
Compute the maximum waiting time w such that you can still reach T safely. If it is impossible even with w = 0, return -1. If you can wait arbitrarily long (never blocked by fire), return a large sentinel value (e.g., 10^9).
grid
as an
m x n
array of characters; for Part B, also
(r, c)
coordinates to block.
w
1 ≤ m, n ≤ 300
(or similar)
S
and one
T
.
F
possible (Part C).