This question evaluates understanding of pathfinding and state-space modeling for shortest-path search on an infinite 2D grid, including static obstacle avoidance and spatiotemporal collision constraints introduced by moving obstacles.
You are given an infinite 2D grid with integer coordinates. From a cell (x, y) you may move in 4 directions (North/South/East/West) by 1 cell per move.
You are given:
start = (sx, sy)
goal = (gx, gy)
blocked
, where each coordinate in
blocked
is permanently impassable.
Return any one shortest valid path from start to goal as a list of coordinates (or directions). If no path exists, return “unreachable”.
Important: the grid is infinite. A naive BFS that expands forever must be avoided; your algorithm should terminate even when goal is unreachable (e.g., goal is fully enclosed by barriers).
Now, in addition to blocked, you are given a list of moving obstacles called parades. Each parade has:
(px, py)
at time
t = 0
{N, S, E, W}
t = 2, 4, 6, ...
; it stays in place at
t = 0, 1
, then moves for
t = 2, 3
, etc.).
Rules:
t+1
, that move is invalid.
Return any minimum-time valid path from start at t=0 to goal (with timestamps implied by step index), or “unreachable”.
As in Part 1, the grid is infinite; ensure your approach does not run forever when the destination cannot be reached.