Code RoomDungeon minimum starting health
HardPrep Room Coding #86

Dungeon minimum starting health

CodingAlgorithms & data structuresSenior–Staff~30 min

A knight enters the top-left cell of an m x n dungeon and must reach the princess in the bottom-right cell, moving only right or down. Each cell adds its integer value to the knight's health (negative cells are damage, positive cells are potions). If the knight's health ever drops to 0 or below, the knight dies. Return the minimum positive starting health that guarantees the knight reaches the princess alive. Grid dimensions are at least 1x1.

Implement
calculate_minimum_hp(dungeon: list[list[int]]) → int
Examples
in[[[-2,-3,3],[-5,-10,1],[10,30,-5]]]out7
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 30 min
InputExpectedGot
[[[-2,-3,3],[-5,-10,1],[10,30,-5]]]7not run yetsample