Skip to main content
Back to problems
#2335
Easy Algorithms

Minimum amount of time to fill cups

Array Greedy Sorting Heap (Priority Queue)
60.0% acceptance
Feb 25, 2026
763
94
You have a water dispenser that can dispense cold, warm, and hot water. Every second, you can fill 2 cups with different types or 1 cup of any type. Return the minimum number of seconds needed to fill all cups.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn fill_cups(amount: Vec<i32>) -> i32 {
    let max_a = *amount.iter().max().unwrap();
    let total: i32 = amount.iter().sum();
    max_a.max((total + 1) / 2)
  }
}