Problem Statement
Given a grid with a starting cell, a destination cell, normal cells, and charging cells, find the optimal path for a robot to reach the destination.
- Each move consumes 1 unit of battery
- Visiting a charging cell recharges the battery to full
- The robot starts with a full battery of capacity
C
Optimize the path in this priority order:
- Minimum charging cells used
- Minimum battery required (max battery needed at any point)
- Minimum total moves
Constraints
1 <= grid dimensions <= 100 x 100- Battery capacity
1 <= C <= 1000 - Grid cells: start
S, destinationD, normal., charging*, obstacle# - Robot moves in 4 directions
Example
S . . *
# # . #
. . . D
Battery capacity = 3
The robot must navigate around obstacles, possibly detour to the charging cell *, and reach D while minimizing charging cells used first, then battery, then moves.
What the Interviewer Expects
- Recognize it's a state-space search — state = (row, col, currentBattery). Not a simple shortest path.
- Multi-criteria optimization — use a priority queue ordered by the lexicographic priority: (chargingCellsUsed, maxBatteryNeeded, moves).
- Modified Dijkstra — the "cost" is a tuple, compared in priority order.
- State tracking — you can revisit a cell with a different battery level, so visited must account for battery state.
- Dry run — walk through a small example showing the priority queue evolution.
Follow-ups
- What if charging cells have a cost (money) to use? How does the optimization change?
- What if the robot can carry a limited number of spare batteries?
- What if some cells drain 2 battery instead of 1 (terrain difficulty)?
- How would you handle a grid too large to fit in memory?