Energy-Optimal Grid Route With a Turn Penalty Around No-Fly Cells
Last updated: November 29, 2026
Quick Overview
On a grid where each cell has an energy cost to enter and some cells are no-fly zones, find the minimum energy for a drone to travel from a start cell to a goal cell when every 90 degree change of heading also costs a fixed penalty.
Zipline
November 29, 20260
0
0 solved
On a grid where each cell has an energy cost to enter and some cells are no-fly zones, find the minimum energy for a drone to travel from a start cell to a goal cell when every 90 degree change of heading also costs a fixed penalty.
Routing around restricted airspace and terrain is core to Zipline's maps and routing work, and real aircraft pay for heading changes. The interviewer checks whether you realise plain Dijkstra on cells is wrong once turns cost energy, and that you expand the state to include heading.
What the Interviewer Expects
- Explain why the state must be (row, col, heading)
- Use Dijkstra since all costs are non-negative
- Compute turn count correctly, including 180 degree reversals
- Handle start or goal inside a no-fly cell
- Give complexity in terms of 4RC states
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
- How would you allow 8 directions with 45 degree turns?
- Wind makes the cost of entering a cell depend on heading; what changes?
- How would A* help here and what heuristic stays admissible?
- The grid is a continent-scale map; how would you make this fast enough?
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 R x C, grid[r][c] >= 0 is the energy to enter the cell, -1 is no-fly. Moving to a 4-neighbour costs that cell's energy plus turn_cost times the number of 90 degree turns from the current ...
High-Level Design
The cost of the next move depends on how you arrived, so a cell alone is not a valid Dijkstra state: a path that reaches a cell more cheaply but facing the wrong way can lose overall. Expand the state...