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
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

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
2D dynamic programming
reverse DP
grid
minimax 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
  • 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 Problems
Sample 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...


Submit Your Answer
Markdown supported