You are given two arrays:
apple → Each element tells how many apples are in a pack.
capacity → Each element tells how many apples each box can hold.
Your goal is to pick as few boxes as possible so that all apples from all packs can fit inside these selected boxes.
You are allowed to split a pack across multiple boxes.
Return the minimum number of boxes needed.
Input: apple = [2, 4, 1] capacity = [3, 6, 2, 5]
Output: 2
Explanation:
Total apples = 2 + 4 + 1 = 7 We choose boxes with capacities 6 and 5. Their total capacity = 11 → enough to store all apples.
Input: apple = [8, 3] capacity = [4, 4, 5]
Output: 3
Explanation:
Total apples = 11 Choosing boxes with capacity 5 and 4 (total = 9) is not enough. So we use boxes: 5 + 4 + 4 = 13 Minimum boxes = 2 (5 and 4 do NOT work, correction: 3 are required). But to keep this example different and simple: Let’s update capacities: [6,5,3] Then min boxes = 2
Accepted:
Submission: