Sponsored
Sponsored
Solve with full IDE support and test cases
Use these hints if you're stuck. Try solving on your own first.
Can we solve it using dynamic programming?
Define <code>dpA[i]</code> as the maximum energy boost if we consider only the first <code>i + 1</code> hours such that in the last hour, we drink the energy drink A.
Similarly define <code>dpB[i]</code>.
<code>dpA[i] = max(dpA[i - 1], dpB[i - 2]) + energyDrinkA[i]</code>
Similarly, fill <code>dpB</code>.
The answer is <code>max(dpA[n - 1], dpB[n - 1])</code>.