Skip to content

Practice Apple Redistribution into Boxes

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#3074
LeetCode Problem

Apple Redistribution into Boxes

Problem Statement

You are given an array apple of size n and an array capacity of size m. There are n packs where the ith pack contains apple[i] apples. There are m boxes as well, and the ith box has a capacity of capacity[i] apples. Return the minimum number of boxes you need to select to redistribute these n packs of apples into boxes. Note that, apples from the same pack can be distributed into different boxes.

Source: Apple Redistribution into Boxes on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
apple = [1,3,2], capacity = [4,3,1,5,2]
Output
2

# Example 2

Input
apple = [5,5,5], capacity = [2,4,2,7]
Output
4

Constraints

1 <= n == apple.length <= 50
1 <= m == capacity.length <= 50
1 <= apple[i], capacity[i] <= 50
The input is generated such that it's possible to redistribute packs of apples into boxes.

Related LeetCode Problems

Practice more problems similar to Apple Redistribution into Boxes.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.