Array Greedy 3207. Maximum Points After Enemy Battles¶ Time: $O(n)$ Space: $O(1)$ C++JavaPython 1 2 3 4 5 6 7 8 9 10 11 12class Solution { public: long long maximumPoints(vector<int>& enemyEnergies, int currentEnergy) { const int minEnergy = ranges::min(enemyEnergies); return currentEnergy < minEnergy ? 0 : (currentEnergy + accumulate(enemyEnergies.begin(), enemyEnergies.end(), 0LL) - minEnergy) / minEnergy; } }; 1 2 3 4 5 6 7 8 9class Solution { public long maximumPoints(int[] enemyEnergies, int currentEnergy) { final int minEnergy = Arrays.stream(enemyEnergies).min().orElse(0); return currentEnergy < minEnergy ? 0 : (currentEnergy + Arrays.stream(enemyEnergies).asLongStream().sum() - minEnergy) / minEnergy; } } 1 2 3 4 5class Solution: def maximumPoints(self, enemyEnergies: list[int], currentEnergy: int) -> int: minEnergy = min(enemyEnergies) return (0 if currentEnergy < minEnergy else (currentEnergy + sum(enemyEnergies) - minEnergy) // minEnergy)