Minimum Starting Battery for a Robot Crossing Charge and Drain Cells
Last updated: November 29, 2026
Quick Overview
A warehouse robot crosses a grid from the top-left to the bottom-right moving only right or down; each cell adds or drains battery, and the battery must stay at least 1 at all times. Return the minimum starting battery.
Amazon
November 29, 20260
0
0 solved
A warehouse robot crosses a grid from the top-left to the bottom-right moving only right or down; each cell adds or drains battery, and the battery must stay at least 1 at all times. Return the minimum starting battery.
Amazon Robotics robots must not strand themselves mid-route, which turns the dungeon game DP into a realistic onsite problem. The interviewer is checking whether you notice that forward DP fails and the DP must run backward from the goal.
What the Interviewer Expects
- Explain why forward DP on max remaining battery is wrong
- Define need[r][c] as the minimum battery on entering (r, c)
- Fill from the bottom-right back to the top-left
- Clamp with max(1, ...)
- O(R * C) time, O(C) space
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
- Give a grid where maximizing remaining battery forward picks the wrong route.
- What if the robot may also move left or up?
- What if the battery has a maximum capacity?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: non-empty grid of integers. Entering a cell applies its value (start cell included). Battery must be at least 1 after every cell. Output: minimum starting battery....
High-Level Design
Forward DP fails because a route that ends with more battery may have dipped too low early. Two quantities matter (minimum reached and final value) and they do not combine into one forward state.
Bac...