3
int solve(int i, int j, int m, int n, vector<vector<int>> &grid) {4
// if we come out of the grid simply return a large value5
if (i >= m || j >= n) return INT_MAX;7
// calucate health by the 2 possible ways8
int down = solve(i + 1, j, m, n, grid);9
int right = solve(i, j + 1, m, n, grid);11
// take the min both both12
int health = min(down, right);14
// we reach the destination when both the sides return INT_MAX15
if (health == INT_MAX) {16
health = 1; // both are +ve large integers so min health required = 120
if (health - grid[i][j] > 0) {21
ans = health - grid[i][j];29
int calculateMinimumHP(vector<vector<int>> &dungeon) {30
int m = dungeon.size();31
int n = dungeon[0].size();33
return solve(0, 0, m, n, dungeon);