Tap here to switch tabs
Problem
Submissions

Problem: Fruits Into Baskets II

med
30 min
Try to solve the Fruits Into Baskets II problem.

Statement

You are given two integer arrays, fruits and baskets, each of length n.

  • fruits[i] represents the quantity of the ithi^{th} type of fruit.

  • baskets[j] represents the capacity of the jthj^{th} basket.

Place the fruit types into baskets from left to right using the following rules:

  1. Each fruit type must be placed in the leftmost available basket whose capacity is greater than or equal to its quantity.

  2. Each basket can hold only one type of fruit.

  3. If a fruit type cannot be placed in any available basket, it remains unplaced.

Return the number of fruit types that remain unplaced after all possible allocations are made.

Constraints:

  • n == fruits.length == baskets.length

  • 11 \leq n 102\leq 10^2

  • 11 \leq fruits[i], baskets[i] 103\leq 10^3

Tap here to switch tabs
Problem
Submissions

Problem: Fruits Into Baskets II

med
30 min
Try to solve the Fruits Into Baskets II problem.

Statement

You are given two integer arrays, fruits and baskets, each of length n.

  • fruits[i] represents the quantity of the ithi^{th} type of fruit.

  • baskets[j] represents the capacity of the jthj^{th} basket.

Place the fruit types into baskets from left to right using the following rules:

  1. Each fruit type must be placed in the leftmost available basket whose capacity is greater than or equal to its quantity.

  2. Each basket can hold only one type of fruit.

  3. If a fruit type cannot be placed in any available basket, it remains unplaced.

Return the number of fruit types that remain unplaced after all possible allocations are made.

Constraints:

  • n == fruits.length == baskets.length

  • 11 \leq n 102\leq 10^2

  • 11 \leq fruits[i], baskets[i] 103\leq 10^3