Space Time Path Planning Past Patrolling Threats on a Grid
Last updated: November 29, 2026
Quick Overview
An aircraft moves on a grid one cell per step (or waits in place), terrain cells are impassable, and each enemy patrol follows a known cyclic route. Return the earliest time the aircraft can reach the goal without ever sharing a cell with a patrol or swapping cells with one in a single step, or -1 if impossible.
Shield AI
November 29, 20260
0
0 solved
An aircraft moves on a grid one cell per step (or waits in place), terrain cells are impassable, and each enemy patrol follows a known cyclic route. Return the earliest time the aircraft can reach the goal without ever sharing a cell with a patrol or swapping cells with one in a single step, or -1 if impossible.
Planning around moving threats is core to autonomous air operations, and a time-expanded search is the simplest exact model of it. This onsite problem checks whether you see that position alone is not a valid state, bound the time dimension with the patrol period, and catch the swap collision that a naive check misses.
What the Interviewer Expects
- Explains why plain BFS over cells is wrong when obstacles move
- Uses state (cell, t mod L) where L is the lcm of patrol periods
- Includes waiting as a move
- Checks both vertex conflicts and edge (swap) conflicts
- Bounds the search and analyzes the state space size
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Patrol periods are 7, 11 and 13. What happens to the state space, and how would you cope?
- Threat positions are only known probabilistically. How does the formulation change?
- Several of our own aircraft must plan together without colliding. What approach would you use?
- How would you turn this grid plan into a flyable trajectory?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Grid with terrain, a list of patrol routes where patrol p is at route[t % len(route)] at time t, start and goal cells. Each step: move in 4 directions or wait. Invalid if the new cell holds a patrol...
High-Level Design
Every move costs one time step, so BFS in the time-expanded graph finds the earliest arrival. The full state is (cell, t), but since all patrols repeat every L = lcm(periods) steps, `(cell, t mod ...