#3207

Maximum Points After Enemy Battles

expert · 1105 · lc medium +32 · 33.2% accepted · 128 likes · top 11%

Description

You are given integer array enemyEnergies and integer currentEnergy. Starting with 0 points and all enemies unmarked, perform operations in any order:

1. Spend enemyEnergies[i] energy to defeat unmarked enemy i and earn 1 point (requires enough energy).

2. If you have at least 1 point, absorb the energy of any unmarked enemy i (currentEnergy += enemyEnergies[i]) and mark them.

Return the maximum points you can accumulate.

Code

1
2
3