You are given two arrays of integers, fruits and baskets, each of length n, where fruits[i] represents the quantity of the ith type of fruit, and baskets[j] represents the capacity of the jth basket.
From left to right, place the fruits according to these rules:
Return the number of fruit types that remain unplaced after all possible allocations are made.
Examples
Example 1
Input: fruits = [4,2,5], baskets = [3,5,4]
Output: 1
Explanation:
Since one fruit type remains unplaced, we return 1.
Example 2
Input: fruits = [3,6,1], baskets = [6,4,7]
Output: 0
Explanation:
Since all fruits are successfully placed, we return 0.
Constraints
n == fruits.length == baskets.length
1 <= n <= 100
1 <= fruits[i], baskets[i] <= 1000
3477. Fruits Into Baskets II
Easy
10 Points
Array
Binary Search
Segment Tree
Simulation
Ordered Set
You are given two arrays of integers, fruits and baskets, each of length n, where fruits[i] represents the quantity of the ith type of fruit, and baskets[j] represents the capacity of the jth basket.
From left to right, place the fruits according to these rules:
Return the number of fruit types that remain unplaced after all possible allocations are made.
Examples
Example 1
Input: fruits = [4,2,5], baskets = [3,5,4]
Output: 1
Explanation:
Since one fruit type remains unplaced, we return 1.
Example 2
Input: fruits = [3,6,1], baskets = [6,4,7]
Output: 0
Explanation:
Since all fruits are successfully placed, we return 0.
Constraints
n == fruits.length == baskets.length
1 <= n <= 100
1 <= fruits[i], baskets[i] <= 1000
Fruits Into Baskets II - Practice Coding | SlaveCode