The Question
Coding
First Fit Fruit Placement
Given an array 'fruits' representing the size of fruits and an array 'baskets' representing the capacity of baskets, simulate the following process: for each fruit in the order they appear, place it in the first available basket (lowest index) that has a capacity greater than or equal to the fruit's size. Once a fruit is placed, that basket is no longer available. Return the total number of fruits that could not be placed in any basket. Optimize the solution to handle arrays of size up to 10^5.
Java
Segment Tree
Range Maximum Query
Binary Search on Tree
March 11, 2026