Dungeon Health
Reported by candidates from Goldman Sachs's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Goldman Sachs reported this one in September 2026, and it's the classic dungeon grid where the knight can only go right or down. The question really reduces to one thing: how much health do you need standing at each cell to survive everything after it. Forget the forward path. If you've got the OA in a day or two, this is a dynamic programming grid problem with a twist that trips people who code it forward. StealthCoder sits invisibly on your screen as a safety net if you blank on the direction of the DP during the live assessment, but the idea is small enough to own tonight.
The problem
A knight starts at the top-left cell of a nonempty rectangular dungeon dungeon and must reach the bottom-right princess cell. From any cell the knight may move only one step right or one step down. Each cell contains an integer. A negative value is damage taken on entry. A nonnegative value is health recovered on entry. The knight's health is an integer that must stay at least 1 after entering every cell, including the start and the destination. Return the minimum initial health that lets the knight reach the princess under an optimal path. What the interview report shared The Superday report asked dungeon health as a dynamic-programming problem. Function calculateMinimumHP(dungeon: int[][]) → int Examples Example 1 dungeon = [[-2,-3,3],[-5,-10,1],[10,30,-5]] return = 7 The path -2, then -3, then 3, then 1, then -5 needs initial health 7. Any cheaper start dies on this dungeon, and every other path needs at least as much. Example 2 dungeon = [[0]] return = 1 The single cell is nonnegative, so the smallest legal starting health is 1. Constraints 1 <= dungeon.length, dungeon[i].length <= 200. dungeon is rectangular: every row has the same length. -1000 <= dungeon[i][j] <= 1000.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is to run the DP backward from the princess. Define need[i][j] as the minimum health required when entering cell (i,j) to finish alive. At the bottom-right, need = max(1, 1 - value). Everywhere else, take the smaller of need to the right and need below, subtract the current cell's value, and clamp at 1: need[i][j] = max(1, min(right, down) - dungeon[i][j]). The answer is need[0][0]. The pitfall is going forward with a max-sum or min-prefix approach. That fails because the best path by total health can still dip below 1 midway, and a greedy choice at each step can't see that. Handle the last row and column by treating out-of-bounds as infinity, with the cell next to the princess seeded at 1. You can use one row of space, so it's O(m*n) time. If the backward recurrence slips out of your head mid-assessment, StealthCoder is the hedge.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Dungeon Health cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as dungeon game. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Goldman Sachs's OA.
Goldman Sachs reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Dungeon Health FAQ
What's the trick in Dungeon Health?+
Work backward from the princess cell. For each cell, compute the minimum health needed on entry as max(1, min(right, down) - value). Forward DP fails because a path with a good total can still drop health to zero partway through. Backward DP bakes in the survival requirement.
How hard is this really for a Goldman Sachs OA?+
It's a hard-tagged grid DP, but the code is about ten lines once you see the backward recurrence. The difficulty is the insight, not the implementation. If you've seen min path sum, you're close. The clamp at 1 is the part people forget.
Why can't I just use min path sum or max path sum?+
Health has to stay at least 1 after every cell, not just at the end. A path with the best total can dip negative early and kill the knight. You need the requirement at each step, which is why the DP stores needed health instead of accumulated health.
How do I handle the edges of the grid?+
Treat cells outside the grid as infinity so the min ignores them. Seed the princess cell as max(1, 1 - dungeon[m-1][n-1]). Then the last row only looks right and the last column only looks down. A padded array with infinity makes this clean.
How do I prep for this in 48 hours?+
Write the backward DP from scratch twice, once with a 2D table and once with a single row. Test with the [[0]] case and the 3x3 example that returns 7. Also check a one-row and one-column grid. That covers the edge cases that usually break submissions.