LeetCode solutions

3334. Apple Redistribution into Boxes

My accepted Python solution to LeetCode problem 3334, Apple Redistribution into Boxes, running in 0ms.

  • Difficulty: Easy
  • Python
  • Runtime 0ms
  • Memory 12.4MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 12.4MB, accepted 2025-12-24.

python
class Solution(object):
    def minimumBoxes(self, apple, capacity):
        total_apples = sum(apple)
        capacity.sort(reverse=True)
        current_capacity = 0
        for i, cap in enumerate(capacity):
            current_capacity += cap
            if current_capacity >= total_apples:
                return i + 1
        return len(capacity)

Source