FastPrepFinal and Maximum Health after Deltas

Final and Maximum Health after Deltas

ZipRecruiter logoZipRecruiter● EasyNEW GRADOA
Learn

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 <= 1000000000
  • 0 <= deltas.length <= 100000
  • Every intermediate value fits in a signed 32-bit integer.

More ZipRecruiter problems

See ZipRecruiter hiring insights
public int[] healthExtremes(int initialHealth, int[] deltas) {
    // Write your code here.
}
initialHealth10
deltas[5,-3,8,-20]
expected[0,20]
Checking account…