Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Dungeon Game

XPChallenge Points: 30
levelLevel: Hard

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 knights 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 knights minimum initial health so he can safely reach the princess.

Example 1:

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.

Example 2:

Input: [[0]]

Output: 1

Explanation:

No damage is taken; at least 1 health point is still required to begin.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result