Trains the technique from
LeetCode 2214Minimum Health to Beat GameThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A machine runs through rounds in order, and round i drains damage[i] charge.
The machine carries one shield of strength armor, which may be used on at most one round. Used on a round, it absorbs that round's drain up to its own strength, so the drain becomes whatever is left over.
The machine must keep strictly more than zero charge at every moment. Return the least charge it can start with and still get through every round.
Example 1
The rounds drain 53 in total. The shield is worth most on the round draining 27, where it absorbs all 12 of its strength, leaving 41 to be paid for and one charge to be kept.
Example 2
The shield is stronger than the only round, so it absorbs the whole drain and the machine needs only the one charge it must keep.
Example 3
Nothing drains at all, so the machine needs only the charge it must keep.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def minimum_health(damage: list[int], armor: int) -> int:public long minimumHealth(int[] damage, int armor)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.