You are given two arrays of length `n`: `fruits[i]` is the quantity of fruit type `i`, and `baskets[j]` is the capacity of basket `j`. Going through the fruits from left to right, place each one in the leftmost basket that is still empty and has capacity at least that quantity. Each basket holds one fruit type. If no basket fits, the fruit stays unplaced. Return the number of unplaced fruit types.
You are given two arrays of length n: fruits[i] is the quantity of fruit type i, and baskets[j] is the capacity of basket j. Going through the fruits from left to right, place each one in the leftmost basket that is still empty and has capacity at least that quantity. Each basket holds one fruit type. If no basket fits, the fruit stays unplaced. Return the number of unplaced fruit types.
Example 1:
Input: {"fruits":[4,2,5],"baskets":[3,5,4]}
Output: 1
Constraints:
n=fruits.length=baskets.length
1≤n≤100
1≤fruits[i],baskets[i]≤1000
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"fruits":[4,2,5],"baskets":[3,5,4]}
fruits (in arrival order)
4
2
5
baskets (height = capacity, the dashed line = current fruit size)
3
#0
5
#1
4
#2
3 fruit type(s) arrive in order and 3 empty baskets wait in a row. Each fruit takes the leftmost free basket that is big enough.