Skip to content

Practice Fruits Into Baskets III

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3479
LeetCode Problem

Fruits Into Baskets III

Problem Statement

Process fruits from left to right. Place the entire quantity fruits[i] into the leftmost unused basket with capacity at least that quantity. A basket can accept only one fruit type. If no basket fits, leave that fruit type unplaced and continue. Return how many fruit types remain unplaced.

Source: Fruits Into Baskets III on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
fruits = [4,2,5], baskets = [3,5,4]
Output
1

# Example 2

Input
fruits = [3,6,1], baskets = [6,4,7]
Output
0

Constraints

n == fruits.length == baskets.length
1 <= n <= 10^5
1 <= fruits[i], baskets[i] <= 10^9

Related LeetCode Problems

Practice more problems similar to Fruits Into Baskets III.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.