Dungeon Game
A knight starts at the top-left of an m x n dungeon and must reach the princess at the bottom-right, moving only right or down. Each cell adds (positive) or subtracts (negative) health; if health ever drops to 0 or below the knight dies. Return the minimum initial health needed to guarantee survival to the goal.
Open official problem prompt ↗Find the smallest starting health so that, following some right/down path, the knight's health stays at least 1 in every cell including the goal.
Planning a desert crossing where each oasis gives or drains water. To know how much water to carry when entering a checkpoint, you must first know how thirsty the road ahead is, so you plan backward from the destination.
- Input
- dungeon = [[-2,-3,3],[-5,-10,1],[10,30,-5]]
- Output
- 7
- Why
- Starting with 7 health the path right,right,down,down keeps health positive at every step; 6 or less fails somewhere.
m == dungeon.lengthn == dungeon[i].length1 <= m, n <= 200-1000 <= dungeon[i][j] <= 1000