FastPrepDungeon Game
Problems/Dungeon Game

Dungeon Game

LotusFlare logoLotusFlare● HardFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: In the first round of a LotusFlare onsite, the coding question was Dungeon Game, named directly.

The report gives no examples, limits or changes to the usual task. Here you get the standard version. A knight moves right or down through a grid of rooms that add or take health. You return the smallest starting health that keeps it alive. The grid limits are added for this practice version.

Our version is about 90% the same as the reported question.

A knight must rescue a princess held in the bottom-right room of a dungeon. The dungeon is an m x n grid of rooms, and the knight starts in the top-left room. From any room the knight can move only one room to the right or one room down.

Each room changes the knight's health by dungeon[r][c]: a negative number is a demon that takes that much health, a positive number is a magic orb that adds health, and 0 is an empty room. The first and the last room count too.

The knight starts with a positive whole number of health points. If the health ever drops to 0 or below, the knight dies. Return the smallest starting health that lets the knight reach the princess alive.

Function

calculateMinimumHP(dungeon: int[][]) → int

Examples

Example 1

dungeon = [[-3,5],[-10,1]]return = 4

Going right then down visits -3, 5, 1. With 4 health the knight has 1 after the first room and stays alive. Going down first meets -3 and then -10, which needs 14. So the answer is 4.

Example 2

dungeon = [[2,-6,1],[-4,3,-2]]return = 3

Going down first visits 2, -4, 3, -2. The running total goes 2, -2, 1, -1, so its lowest point is -2 and the knight needs 3 health to stay at 1 or more. The other two paths both enter the -6 room and fall to -4 or lower, so they need at least 5. The answer is 3.

Example 3

dungeon = [[0]]return = 1

The only room is empty, but the knight's health must always be positive, so the answer is 1.

Constraints

  • m == dungeon.length
  • n == dungeon[i].length
  • 1 <= m, n <= 200
  • -1000 <= dungeon[i][j] <= 1000

More LotusFlare Onsite Interview questions

  • LRU CacheONSITE INTERVIEW · Seen Nov 2026
  • Sliding Window Rate LimiterONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Dungeon GameAmazon · ONSITE INTERVIEW
  • Maximum Non-Adjacent Coins in Two RowsKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Longest Increasing Path in a MatrixNew Relic · PHONE SCREEN · ONSITE INTERVIEW
  • Longest Increasing Path in a MatrixVisa · ONSITE INTERVIEWVisa interview questions
  • Maximal Rectangle in a Binary MatrixGoogle · ONSITE INTERVIEWGoogle interview questions
  • Dungeon HealthGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • DSA Round: Maximum Score Grid PathOpenAI · ONSITE INTERVIEWOpenAI interview questions
  • Longest Decreasing Matrix Path with Limited RelaxationsDuolingo · ONSITE INTERVIEWDuolingo interview questions
  • Longest Increasing Path in a MatrixDoorDash · ONSITE INTERVIEWDoorDash interview questions
  • Maximum All-Ones Square Side LengthOmnissa · ONSITE INTERVIEWOmnissa interview questions
See LotusFlare hiring insights
Saved
class Solution {
    public int calculateMinimumHP(int[][] dungeon) {
        // Write your code here.
    }
}
Checking account…