LeetCode solutions

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

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 15ms, memory 17.2MB, accepted 2025-12-29.

python
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

Source