Tap here to switch tabs
Problem
Submissions

Problem: Fruits Into Baskets III

Try to solve the Fruits Into Baskets III problem.

Statement

You are given two integer arrays of length n, named fruits and baskets. Here, fruits[i] denotes the quantity of the ithi^{th} fruit type, and baskets[j] denotes the capacity of the jthj^{th} basket.

Starting from the first fruit at index 00 to the last fruit at index n−1n - 1, each fruit is placed into the leftmost available basket whose capacity is greater than or equal to the quantity of that fruit. Once a basket is used, it cannot hold any other fruit. If there is no available basket with sufficient capacity, that fruit remains unplaced.

Return the number of fruits that cannot be placed into any basket.

Constraints:

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

  • 1≤1 \le n ≤105\le 10^5

  • 1≤1 \le fruits[i], baskets[i] ≤109\le 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Fruits Into Baskets III

Try to solve the Fruits Into Baskets III problem.

Statement

You are given two integer arrays of length n, named fruits and baskets. Here, fruits[i] denotes the quantity of the ithi^{th} fruit type, and baskets[j] denotes the capacity of the jthj^{th} basket.

Starting from the first fruit at index 00 to the last fruit at index n−1n - 1, each fruit is placed into the leftmost available basket whose capacity is greater than or equal to the quantity of that fruit. Once a basket is used, it cannot hold any other fruit. If there is no available basket with sufficient capacity, that fruit remains unplaced.

Return the number of fruits that cannot be placed into any basket.

Constraints:

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

  • 1≤1 \le n ≤105\le 10^5

  • 1≤1 \le fruits[i], baskets[i] ≤109\le 10^9