leetle

Daily challenge for 2026-04-17

472. Maximum Harvest Energy

You are given an array of integers representing the energy yield of crops in a row. You can harvest any crop, but harvesting a crop requires 1 unit of energy from your battery to process. Your goal is to find the maximum net energy you can obtain. Net energy is the sum of the yields of harvested crops minus the number of crops harvested. If the maximum net energy is negative, return 0.

Example:
Input: yields = [4, 1, 5, 0, 2]
Output: 7
(Explanation: Harvest crops with yields 4, 5, and 2. Net energy = (4+5+2) - 3 = 8. Wait, 4-1=3, 1-1=0, 5-1=4, 0-1=-1, 2-1=1. Sum of positive net gains: 3 + 0 + 4 + 1 = 8. Actually, harvesting the '1' also results in 1-1=0, which doesn't hurt. Total: (4-1) + (5-1) + (2-1) = 8.)

Run this challenge interactively in Python or JavaScript when the app loads.