304 North Cardinal St.
Dorchester Center, MA 02124

# Minimum Amount of Time to Fill Cups LeetCode Solution

## Problem – Minimum Amount of Time to Fill Cups LeetCode Solution

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:

Input: amount = [1,4,2]
Output: 4
Explanation: One way to fill up the cups is:
Second 1: Fill up a cold cup and a warm cup.
Second 2: Fill up a warm cup and a hot cup.
Second 3: Fill up a warm cup and a hot cup.
Second 4: Fill up a warm cup.
It can be proven that 4 is the minimum number of seconds needed.

Example 2:

Input: amount = [5,4,4]
Output: 7
Explanation: One way to fill up the cups is:
Second 1: Fill up a cold cup, and a hot cup.
Second 2: Fill up a cold cup, and a warm cup.
Second 3: Fill up a cold cup, and a warm cup.
Second 4: Fill up a warm cup, and a hot cup.
Second 5: Fill up a cold cup, and a hot cup.
Second 6: Fill up a cold cup, and a warm cup.
Second 7: Fill up a hot cup.

Example 3:

Input: amount = [5,0,0]
Output: 5
Explanation: Every second, we fill up a cold cup.

Constraints:

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

### Minimum Amount of Time to Fill Cups LeetCode Solution in Java

public int fillCups(int[] A) {
int mx = 0, sum = 0;
for(int a: A) {
mx = Math.max(a, mx);
sum += a;
}
return Math.max(mx, (sum + 1) / 2);
}

### Minimum Amount of Time to Fill Cups LeetCode Solution in C++

int fillCups(vector<int>& A) {
int mx = 0, sum = 0;
for(int& a: A) {
mx = max(a, mx);
sum += a;
}
return max(mx, (sum + 1) / 2);
}

### Minimum Amount of Time to Fill Cups LeetCode Solution in Python

def fillCups(self, A):
return max(max(A), (sum(A) + 1) // 2)
##### Minimum Amount of Time to Fill Cups LeetCode Solution Review:

In our experience, we suggest you solve this Minimum Amount of Time to Fill Cups LeetCode Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Minimum Amount of Time to Fill Cups LeetCode Solution

Find on LeetCode

##### Conclusion:

I hope this Minimum Amount of Time to Fill Cups LeetCode Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions