Minimum Starting Health to Win the Game
Learn this problemProblem statement
Note - Similar to LC 2214
In Amazon Prime Games, a player needs to pass n rounds sequentially. The rules are as follows:
power[i] health to complete round i.min(armor, power[i]) for that round.You need to determine the minimum starting health required for the player to win the game.
Thank you so much, Spike! 😊
Function
minimumStartingHealth(power: int[], armor: int) → intExamples
Example 1
power = [1, 2, 6, 7]armor = 5return = 12
Starting health = 12
Round 1: Health = 12 - 1 = 11
Round 2: Health = 11 - 2 = 9
Round 3: Health = 9 - (6 - 5) = 8
Round 4: Health = 8 - 7 = 1
The minimum starting health required to win the game is 12.
Example 2
power = [1, 2, 3]armor = 1return = 6
Starting health = 6
Round 1: Health = 6 - 1 + 1 (armor) = 6
Round 2: Health = 6 - 2 = 4
Round 3: Health = 4 - 3 = 1
The minimum starting health required to win the game is 6.