Code Room
CodingHardcod-g029
Subject Dynamic programming 2dLevel Senior–Staff~30 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.