Trains the technique from
LeetCode 3477Fruits Into Baskets IIThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
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.
Example 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
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
Every bin is smaller than every crate, so nothing can be placed.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def num_of_unplaced_fruits(fruits: list[int], baskets: list[int]) -> int:public int numOfUnplacedFruits(int[] fruits, int[] baskets)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.