Minimum Starting Battery for a Robot Crossing a Charging Grid

Last updated: November 29, 2026

Quick Overview

A delivery robot moves right or down from the top-left to the bottom-right of a grid. Each cell drains (negative) or recharges (positive) its battery, and the battery must stay at least 1 at all times. Return the minimum starting charge.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


A delivery robot moves right or down from the top-left to the bottom-right of a grid. Each cell drains (negative) or recharges (positive) its battery, and the battery must stay at least 1 at all times. Return the minimum starting charge.

Asked in Meta onsites because the obvious forward DP is wrong, and the interviewer wants to see you discover why and switch to a backward DP. It probes whether you reason about what state the future needs rather than what the past achieved.

What the Interviewer Expects
  • Show why forward DP on max remaining charge fails
  • Define need[i][j] as the minimum charge required on entering cell (i, j)
  • Compute it from the bottom-right corner backwards
  • Clamp needs to at least 1
  • Use one row of memory
Key Topics to Cover
Backward dynamic programming
Grid DP
Dungeon game pattern
Clamping
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
  • Why exactly does a forward DP fail? Give a counterexample.
  • How would you also print the path?
  • What if the robot may also move left or up?
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 is a non-empty r x c integer grid. The robot enters (0, 0) with charge h, adds each cell's value on entry (including the first and last), and dies if the charge ever drops below 1. Return ...

High-Level Design

Forward DP fails because two quantities matter, the lowest point along the way and the final charge, and maximizing one can hurt the other. Going backwards collapses this. Let need[i][j] be the mini...


Submit Your Answer
Markdown supported