The Question
CodingFirst-Fit Decreasing Variation with Baskets
You are given two integer arrays, 'fruits' representing the sizes of fruits and 'baskets' representing the capacities of available baskets. You must process each fruit in the order they appear and place each fruit into the first (leftmost) available basket that has a capacity greater than or equal to the fruit's size. Each basket can only be used once. Implement an efficient solution to determine the total number of fruits that remain unplaced after all fruits have been processed, assuming the number of elements can be up to 10^5.
Java
Segment Tree
Tree Walking
Greedy
March 11, 2026