Skip to content

2335. Minimum Amount of Time to Fill Cups 👍

  • Time: $O(n)$
  • Space: $O(1)$
1
2
3
4
5
6
7
8
class Solution {
 public:
  int fillCups(vector<int>& amount) {
    const int mx = ranges::max(amount);
    const int sum = accumulate(amount.begin(), amount.end(), 0);
    return max(mx, (sum + 1) / 2);
  }
};
1
2
3
4
5
6
7
class Solution {
  public int fillCups(int[] amount) {
    final int mx = Arrays.stream(amount).max().getAsInt();
    final int sum = Arrays.stream(amount).sum();
    return Math.max(mx, (sum + 1) / 2);
  }
}
1
2
3
class Solution:
  def fillCups(self, amount: list[int]) -> int:
    return max(max(amount), (sum(amount) + 1) // 2)