Class Solution
-
- All Implemented Interfaces:
public final class Solution3074 - Apple Redistribution into Boxes.
Easy
You are given an array
appleof sizenand an arraycapacityof sizem.There are
npacks where the <code>i<sup>th</sup></code> pack containsapple[i]apples. There aremboxes as well, and the <code>i<sup>th</sup></code> box has a capacity ofcapacity[i]apples.Return the minimum number of boxes you need to select to redistribute these
npacks of apples into boxes.Note that, apples from the same pack can be distributed into different boxes.
Example 1:
Input: apple = 1,3,2, capacity = 4,3,1,5,2
Output: 2
Explanation: We will use boxes with capacities 4 and 5. It is possible to distribute the apples as the total capacity is greater than or equal to the total number of apples.
Example 2:
Input: apple = 5,5,5, capacity = 2,4,2,7
Output: 4
Explanation: We will need to use all the boxes.
Constraints:
1 <= n == apple.length <= 501 <= m == capacity.length <= 501 <= apple[i], capacity[i] <= 50The input is generated such that it's possible to redistribute packs of apples into boxes.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntegerminimumBoxes(IntArray apple, IntArray capacity)-
-
Method Detail
-
minimumBoxes
final Integer minimumBoxes(IntArray apple, IntArray capacity)
-
-
-
-