Final and Maximum Health after Deltas
Problem statement
Start at initialHealth and apply every signed delta in order without clamping. Return [finalHealth, maximumHealth], where the maximum includes the initial state.
Function
healthExtremes(initialHealth: int, deltas: int[]) → int[]Examples
Example 1
initialHealth = 10deltas = [5,-3,8,-20]return = [0,20]The final and peak values occur at different times.
Example 2
initialHealth = 7deltas = [-1,-2]return = [4,7]The initial state remains the maximum.
Constraints
-1000000000 <= initialHealth <= 10000000000 <= deltas.length <= 100000- Every intermediate value fits in a signed 32-bit integer.