Minimum Amount of Time to Fill Cups

You have a water dispenser that can dispense cold, warm, and hot water. Every second, you can either fill up 2 cups with different types of water, or 1 cup of any type of water.

You are given a 0-indexed integer array amount of length 3 where amount[0], amount[1], and amount[2] denote the number of cold, warm, and hot water cups you need to fill respectively. Return the minimum number of seconds needed to fill up all the cups.

Example 1
Inputamount = [1,4,2]
Output4
One optimal way fills two different types when possible and finishes all cups in 4 seconds, which is the minimum.
Example 2
Inputamount = [5,4,4]
Output7
An optimal schedule fills all cups in 7 seconds by pairing different water types whenever possible.

Constraints

  • amount.length == 3
  • 0 <= amount[i] <= 100

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