-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFruits Into Baskets II.py
More file actions
24 lines (17 loc) · 985 Bytes
/
Fruits Into Baskets II.py
File metadata and controls
24 lines (17 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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:
def numOfUnplacedFruits(self, fruits: List[int], baskets: List[int]) -> int:
placed = 0
n = len(fruits)
for i in range(n):
for j in range(n):
if fruits[i] <=baskets[j]:
baskets[j] = -1
placed +=1
break
return n - placed