Dungeon Game
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
A knight enters a dungeon laid out as an m x n grid at the top-left cell and must reach the princess in the bottom-right cell, moving only right or down.
Each cell holds an integer: a negative value is damage the knight takes on entering it, a positive value is health restored, and 0 does nothing. The first and last cells apply their values too. If the knight's health ever drops to 0 or below, he dies immediately.
Return the smallest positive integer starting health that lets the knight reach the princess alive along some path.
Examples
Constraints
- 1 <= m, n <= 200
- -1000 <= dungeon[i][j] <= 1000
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.