السلام عليكم
دي المساله
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:
Each fruit type must be placed in the leftmost available basket with a capacity greater than or equal to the quantity of that fruit type.
Each basket can hold only one type of fruit.
If a fruit type cannot be placed in any basket, it remains unplaced.
Return the number of fruit types that remain unplaced after all possible allocations are made.
ودي الكود بتاعي فا انا عاوز اعرف اي المشكله في الكود وهل فيه افضل من كده
class Solution(object):
def numOfUnplacedFruits(self, fruits, baskets):
"""
:type fruits: List[int]
:type baskets: List[int]
:rtype: int
"""
fruits.sort()
baskets.sort()
f_index = 0
b_index = 0
while f_index < len(fruits) and b_index < len(baskets):
if fruits[f_index] <= baskets[b_index]:
f_index += 1
b_index += 1
return len(fruits) - f_index
solution = Solution()
print(solution.numOfUnplacedFruits([4, 2, 5], [3, 5, 4]))
print(solution.numOfUnplacedFruits([3, 6, 1], [6, 4, 7]))