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
Coding & Algorithms
Software Engineer
Samsung
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Hard

0

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
state-space BFS
dominance pruning
grid graphs
resource constraints
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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 ...


Submit Your Answer
Markdown supported

Related Questions