A tax collector must travel through an N × M dungeon to collect revenue records.
Each cell in the dungeon affects the collector's Health Points (HP):
The collector starts at the top-left cell (0,0) and must reach the bottom-right cell (N-1, M-1).
At every step, the collector may move only:
The collector's HP must never drop to 0 or below at any point during the journey.
Determine the minimum initial HP required to guarantee survival until reaching the destination.
Print a single integer representing the minimum initial HP required.
1 ≤ N, M ≤ 200-1000 ≤ dungeon[i][j] ≤ 10003
3
-2 -3 3
-5 -10 1
10 30 -5
7
Starting with 7 HP, one optimal path is:
(0,0) → (0,1) → (0,2) → (1,2) → (2,2)
HP during the journey:
7 → 5 → 2 → 5 → 6 → 1
The HP never becomes 0 or negative, so the minimum required initial HP is 7.
Intuit • Pending
Intuit • Pending
Intuit • Pending
Flipkart • Pending