Assign each fruit to the leftmost basket that can still hold it, then report how many fruits remain unplaced.
Fruits Into Baskets III
You are given two integer arrays, fruits and baskets, of the same length n.
Think of the i-th fruit as having size fruits[i], and the i-th basket as having capacity baskets[i].
You must process the fruits from left to right. For each fruit, place it into the leftmost basket that has not been used yet and whose capacity is at least the fruit size. If no such basket exists, that fruit cannot be placed.
Return the number of fruits that cannot be placed into any basket.
This is a greedy placement problem: every fruit should take the earliest feasible basket so that later fruits still have the best chance to fit.
Input Format
Input
fruits: an integer array of fruit sizesbaskets: an integer array of basket capacities
Both arrays have the same length n.
Output Format
Output
- Return an integer representing how many fruits cannot be placed.
Constraints
1 <= n <= $10^{5}$0 <= fruits[i], baskets[i] <= $10^{9}$- Each basket can be used at most once.
- Process fruits in the given order.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.