Skip to content

Practice Maximum Points After Enemy Battles

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3207
LeetCode Problem

Maximum Points After Enemy Battles

Problem Statement

Start with currentEnergy, zero points, and all enemies in enemyEnergies unmarked. You may fight an unmarked enemy whose energy you can afford: subtract that energy and gain one point, leaving the enemy unmarked. Alternatively, if you already have at least one point, you may mark an unmarked enemy and add its energy to yours; this action does not spend a point. Repeat either action any number of times and return the maximum points obtainable.

Source: Maximum Points After Enemy Battles on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
enemyEnergies = [3,2,2], currentEnergy = 2
Output
3

# Example 2

Input
enemyEnergies = [2] , currentEnergy = 10
Output
5

Constraints

1 <= enemyEnergies.length <= 10^5
1 <= enemyEnergies[i] <= 10^9
0 <= currentEnergy <= 10^9

Related LeetCode Problems

Practice more problems similar to Maximum Points After Enemy Battles.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.