Treasure Hunter
Problem statement
You start at the top-left cell of a dungeon with 5 health. Move orthogonally through spaces. X is a wall, a digit is a trap that deals that much damage, H is a potion that restores 10 health, and T is the treasure.
A trap or potion applies only the first time that path enters its cell. Health must remain positive. Return [minimumSteps, maximumRemainingHealth], maximizing health only among minimum-step surviving paths. Return [-1, 5] when no path reaches a treasure.
Function
treasureHunter(dungeon: String[]) → int[]Examples
Example 1
dungeon = [" X","2T"]return = [2,3]The two-step path triggers damage 2 and reaches the treasure with health 3.
Example 2
dungeon = [" H"," XX"," 9T"]return = [8,6]The shortest surviving route first takes the potion, then survives the damage-9 trap with health 6.
Example 3
dungeon = [" X","XT"]return = [-1,5]Walls isolate the treasure.
Constraints
1 <= rows, columns <= 12.- The grid contains spaces,
X, digits,H, and zero or oneT. - The top-left cell is a space.
- At most 15 trap and potion cells appear.