Maximum Energy Boost From Two Drinks

You are given two integer arrays energyDrinkA and energyDrinkB of the same length n by a futuristic sports scientist. These arrays represent the energy boosts per hour provided by two different energy drinks, A and B, respectively.

You want to maximize your total energy boost by drinking one energy drink per hour. However, if you want to switch from consuming one energy drink to the other, you need to wait for one hour to cleanse your system, meaning you will not get any energy boost in that hour.

Return the maximum total energy boost you can gain in the next n hours.

Note that you can start consuming either of the two energy drinks.

Example 1
InputenergyDrinkA = [1,3,1], energyDrinkB = [3,1,1]
Output5
To gain an energy boost of 5, drink only energy drink A or only energy drink B.
Example 2
InputenergyDrinkA = [4,1,1], energyDrinkB = [1,1,3]
Output7
Drink energy drink A for the first hour, switch and lose the second hour's boost, then gain energy drink B's boost in the third hour for a total of 7.

Constraints

  • n == energyDrinkA.length == energyDrinkB.length
  • 3 <= n <= 10^5
  • 1 <= energyDrinkA[i], energyDrinkB[i] <= 10^5

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate