Skip to main content
Back to problems
Leetcode
Medium
Arrays
Dynamic Programming
Google
Microsoft
Maximum Energy Boost From Two Drinks

Choose at most one drink per hour from two energy-drink sequences, without taking from the same drink in consecutive hours, to maximize total energy boost.

Acceptance 0%
Problem Statement

Problem

You are given two arrays of integers, drink1 and drink2, each representing the energy boost you gain from drinking one bottle at each hour.

You may choose at most one drink in each hour, and if you drink at hour i, then on hour i + 1 you may not choose the same drink again.

Your task is to compute the maximum total energy boost you can obtain.

In other words:

  • At each hour, you may skip drinking.
  • If you choose from drink1 at hour i, then at hour i+1 you cannot choose drink1 again.
  • If you choose from drink2 at hour i, then at hour i+1 you cannot choose drink2 again.
  • You want the largest possible sum of boosts over all hours.

Notes

  • The two arrays have the same length.
  • You may choose no drink at some hours.
  • The goal is to maximize the total sum, not the number of drinks chosen.

Input Format

  • Two integer arrays drink1 and drink2
  • drink1.length == drink2.length == n
  • drink1[i] and drink2[i] are the boosts available at hour i from each drink

Output Format

  • Return a single integer: the maximum total energy boost achievable under the constraints.

Constraints

  • 1 <= n <= $10^{5}$
  • $-10^{9}$ <= drink1[i], drink2[i] <= $10^{9}$
  • Choose at most one drink per hour
  • The same drink cannot be chosen in two consecutive hours
Examples
Sample cases returned by the problem API.

Example 1

Input

drink1 = [4, 2, 7]
drink2 = [1, 5, 3]

Output

12

Explanation

One optimal plan is:

  • Hour 0: take drink1 = 4
  • Hour 1: take drink2 = 5
  • Hour 2: take drink1 = 7

Total = 4 + 5 + 7 = 16.

If the intended interpretation is that you can take only one drink total per hour and cannot take both, this sequence is valid because the chosen drink alternates each hour.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.