Magicsheet logo

Minimum Amount of Time to Fill Cups

Easy
12.5%
Updated 8/1/2025

Minimum Amount of Time to Fill Cups

What is this problem about?

In the Minimum Amount of Time to Fill Cups problem, you have a water dispenser that can fill two different types of cups simultaneously or one cup at a time. You are given an array of three integers representing the number of cups of "cold", "warm", and "hot" water needed. You want to find the minimum number of seconds to fill all cups, assuming each "fill" operation (whether for one or two cups) takes exactly 1 second.

Why is this asked in interviews?

This Minimum Amount of Time to Fill Cups interview question is popular at Google because it's a "brain teaser" wrapped in a coding problem. It tests Greedy thinking and mathematical observation. It's essentially a task-scheduling problem where you want to maximize the "pairing" of tasks to finish as quickly as possible.

Algorithmic pattern used

The Greedy with Heap interview pattern is a robust way to solve this. At each step, you always choose to fill the two types of cups that have the most remaining requirements. By using a Max-Heap (Priority Queue), you can always pick the top two, decrement them, and push them back if they are still non-zero. Alternatively, there is a mathematical O(1)O(1) solution involving max(max_val, ceil(sum / 2)).

Example explanation

Cups needed: [5, 4, 4] (Cold, Warm, Hot).

  1. Fill Cold and Warm: [4, 3, 4]. (1s)
  2. Fill Cold and Hot: [3, 3, 3]. (1s)
  3. Fill Warm and Hot: [3, 2, 2]. (1s) ...and so on. By always pairing the largest two, you reduce the total count most effectively. If you have [5, 0, 0], you have no choice but to fill them one by one, taking 5 seconds.

Common mistakes candidates make

  • Not pairing optimally: Pairing the smallest values first, which might leave a large number of a single type at the end that must be filled individually.
  • Overcomplicating the logic: Using complex recursion when a simple while loop with a heap or a sorting step is enough.
  • Missing the O(1)O(1) insight: While the heap solution is good, the best candidates will recognize the mathematical boundary: you can't finish faster than the largest single requirement, and you can't finish faster than half the total sum.

Interview preparation tip

Whenever you have to "reduce" a set of numbers by taking two at a time, always consider if a Greedy approach using the largest elements is optimal. This logic applies to problems like "Last Stone Weight" and "Organize String."

Similar Questions