Fruits Into Baskets II
Real-world version: Crates That Find No BinThe statement here is our own: the same inputs, outputs and technique.
Crate sizes are given as fruits and bin capacities as baskets, both of the same length.
The crates are dealt with in the order listed. Each crate goes into the leftmost bin not yet used whose capacity is at least the crate's size; a bin holds at most one crate. A crate with no such bin left is unplaced.
Return how many crates end up unplaced.
Examples
Example 1
- Input
- fruits = [14, 3, 27, 9], baskets = [10, 30, 5, 20]
- Output
- 1
The crate of 14 takes the bin of 30, since the bin of 10 is too small. The crate of 3 takes the bin of 10. The crate of 27 finds nothing big enough left, and the crate of 9 takes the bin of 20.
Example 2
- Input
- fruits = [3, 1], baskets = [1, 3]
- Output
- 0
The crate of 3 takes the second bin, and the crate of 1 takes the first, which was passed over as too small the first time.
Example 3
- Input
- fruits = [7, 7, 7], baskets = [6, 6, 6]
- Output
- 3
Every bin is smaller than every crate, so nothing can be placed.
Constraints
- fruits.length == baskets.length
- 1 <= fruits.length <= 100
- 1 <= fruits[i] <= 1000
- 1 <= baskets[i] <= 1000
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def num_of_unplaced_fruits(fruits: list[int], baskets: list[int]) -> int:public int numOfUnplacedFruits(int[] fruits, int[] baskets)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 10 test cases: 10 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's