3790. Fruits Into Baskets II
My accepted Python solution to LeetCode problem 3790, Fruits Into Baskets II, running in 15ms.
- Difficulty: Easy
- Python
- Runtime 15ms
- Memory 17.2MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 15ms, memory 17.2MB, accepted 2025-12-29.
class Solution:
def numOfUnplacedFruits(self, fruits: List[int], baskets: List[int]) -> int:
unplaced = 0
used = [False] * len(baskets)
for fruit in fruits:
placed = False
for j in range(len(baskets)):
if not used[j] and baskets[j] >= fruit:
used[j] = True
placed = True
break
if not placed:
unplaced += 1
return unplaced