A brave knight must travel through a 2D dungeon grid to rescue a princess locked in the bottom-right room.
• Each cell contains an integer:
o Negative ➜ a demon that reduces the knight’s health.
o Zero ➜ empty room (no effect).
o Positive ➜ a magic orb that restores health.
• The knight starts at the top-left cell and
may only move right or down.
• If his health ever drops to 0 or below, he
dies.
Goal: Find the knight’s minimum initial health so he can
safely reach the princess.
Input: [[-2,-3, 3], [-5,-10,1], [10,30,-5]]
Output: 7
Explanation:
An optimal path is Right → Right → Down → Down. The knight must start with at least 7 health to survive all demon encounters.
Input: [[0]]
Output: 1
Explanation:
No damage is taken; at least 1 health point is still required to begin.
Accepted:
Submission: