Shortest Route for a Delivery Robot With Limited Battery and Chargers
Last updated: November 29, 2026
Quick Overview
On a grid with walls '#', open cells '.', charging pads 'C', a start 'S' and a target 'T', a robot spends one battery unit per move and has capacity B; stepping onto a pad refills it to B. Return the minimum number of moves to reach T, or -1.
Samsung
November 29, 20260
0
0 solved
On a grid with walls '#', open cells '.', charging pads 'C', a start 'S' and a target 'T', a robot spends one battery unit per move and has capacity B; stepping onto a pad refills it to B. Return the minimum number of moves to reach T, or -1.
This is the kind of state-space BFS Samsung's advanced coding certification problems favor: the position alone is not the state, so plain BFS gives wrong answers. It also mirrors real planning constraints for Samsung's home robots and battery-limited devices.
What the Interviewer Expects
- Recognizes the state is (row, col, battery), not just (row, col)
- Uses BFS because every move costs one
- Applies dominance pruning: revisit a cell only with strictly more battery
- Handles refill on pads and the zero-battery stop correctly
- Gives O(R*C*B) worst-case bound and explains why pruning usually beats it
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
- Moves now have different energy costs per terrain. What algorithm do you switch to?
- Charging takes k turns. How do you model that?
- Return the actual path, not only its length.
- How would you handle B up to 10^9?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Minimize moves, not battery. The robot may arrive at T with 0 battery but cannot move while at 0. Pads may be revisited. Start begins with full battery....
High-Level Design
Naive BFS on cells fails: the first time we reach a cell may be with less battery than a slightly longer route that passed a charger, and that longer route might be the only one that finishes. So the ...