Tap here to switch tabs
Problem
Submissions

Problem: Minimum Health to Beat Game

Try to solve the Minimum Health to Beat Game problem.

Statement

You are playing a game with n levels, numbered from 00 to n −1- 1. You are given a 00 indexed integer array damage of length n, where damage[i] represents the amount of damage you take at level i.

You are also given an integer armor. You may use your armor ability at most once across all levels. When activated at level i, your armor prevents up to armor damage, meaning you will take max⁡(0,\max(0, damage[i] −- `armor})) damage at that level instead.

To complete the game, your health must remain strictly greater than 00 at all times.

Return the minimum initial health needed to complete all levels of the game.

Constraints:

  • n == damage.length

  • 1≤1 \leq n ≤105\leq 10^5

  • 0≤0 \leq damage[i] ≤105\leq 10^5

  • 0≤0 \leq armor ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Health to Beat Game

Try to solve the Minimum Health to Beat Game problem.

Statement

You are playing a game with n levels, numbered from 00 to n −1- 1. You are given a 00 indexed integer array damage of length n, where damage[i] represents the amount of damage you take at level i.

You are also given an integer armor. You may use your armor ability at most once across all levels. When activated at level i, your armor prevents up to armor damage, meaning you will take max⁡(0,\max(0, damage[i] −- `armor})) damage at that level instead.

To complete the game, your health must remain strictly greater than 00 at all times.

Return the minimum initial health needed to complete all levels of the game.

Constraints:

  • n == damage.length

  • 1≤1 \leq n ≤105\leq 10^5

  • 0≤0 \leq damage[i] ≤105\leq 10^5

  • 0≤0 \leq armor ≤105\leq 10^5