The Question
CodingFruits Into Baskets II
You are given two integer arrays,
fruits and baskets, both of size n. The array fruits[i] represents the quantity of the $i$-th fruit, and baskets[j] represents the capacity of the $j$-th basket.
You must process the fruits in the order they appear in the fruits array. For each fruit, you want to place it into the first available basket (the one with the smallest index) that has a capacity greater than or equal to the fruit's quantity. Once a fruit is placed in a basket, that basket becomes unavailable for any other fruits. If a fruit cannot fit into any available basket, it remains unplaced.
Return the total number of fruits that could not be placed in any basket.
Constraints:
- n == fruits.length == baskets.length
- 1 <= n <= 10^5
- 1 <= fruits[i], baskets[i] <= 10^9Java
Segment Tree