You have fruits[i], the quantity of each fruit type in order, and baskets[j], the capacity of each basket from left to right. Place the fruits one at a time in the given order. Each fruit goes in the leftmost basket that is still empty and whose capacity is at least the fruit's quantity. Each basket holds at most one fruit type. A fruit with no suitable basket stays unplaced.
Write numOfUnplacedFruits(fruits, baskets) returning how many fruit types stay unplaced. A scan for each fruit is O(n) and gives O(n^2) overall; aim for O(n log n).