The Fruits Into Baskets III interview question is identical in structure to "Fruits Into Baskets II". You are given an array of fruit quantities and an array of basket capacities. For each fruit, you must find the first basket (lowest index) that can hold it, and then mark that basket as used. You return the number of unplaced fruits. The difference is usually in the constraints: Version III typically has much larger input sizes, strictly requiring an solution.
This is a classic "Hard" problem asked by companies like Bloomberg and Amazon to filter candidates based on their mastery of advanced data structures. The Segment Tree interview pattern is absolutely mandatory here. It tests not just the knowledge of the data structure, but the ability to implement a custom query logic (finding the first valid index rather than just a range max/sum) efficiently.
This problem relies entirely on a Segment Tree for Range Maximum Queries.
baskets array in its represented range.x:
tree[root] < x, return -1 (cannot be placed).fruits = [4, 2, 5], baskets = [3, 5, 4]
[0, 2] with max 5. Left child [0, 1] max 5, Right child [2, 2] max 4.Segment Trees can be intimidating to write from scratch during an interview. Practice a template for Point Update and Range Max Query. Focus specifically on the logic for routing the search to the left or right child based on the left child's maximum value.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| My Calendar I | Medium | Solve | |
| Fruits Into Baskets II | Easy | Solve | |
| Minimum Absolute Difference Between Elements With Constraint | Medium | Solve | |
| Falling Squares | Hard | Solve | |
| Amount of New Area Painted Each Day | Hard | Solve |