3477. Fruits Into Baskets II Easy

@problem@discussion
#Array#Binary Search#Segment Tree#Simulation#Ordered Set



1/**
2 * [3477] Fruits Into Baskets II
3 *
4 * You are given two arrays of integers, fruits and baskets, each of length n, where fruits[i] represents the quantity of the i^th type of fruit, and baskets[j] represents the capacity of the j^th basket.
5 * From left to right, place the fruits according to these rules:
6 * 
7 * 	Each fruit type must be placed in the leftmost available basket with a capacity greater than or equal to the quantity of that fruit type.
8 * 	Each basket can hold only one type of fruit.
9 * 	If a fruit type cannot be placed in any basket, it remains unplaced.
10 * 
11 * Return the number of fruit types that remain unplaced after all possible allocations are made.
12 *  
13 * <strong class="example">Example 1:
14 * <div class="example-block">
15 * Input: <span class="example-io">fruits = [4,2,5], baskets = [3,5,4]</span>
16 * Output: <span class="example-io">1</span>
17 * Explanation:
18 * 
19 * 	fruits[0] = 4 is placed in baskets[1] = 5.
20 * 	fruits[1] = 2 is placed in baskets[0] = 3.
21 * 	fruits[2] = 5 cannot be placed in baskets[2] = 4.
22 * 
23 * Since one fruit type remains unplaced, we return 1.
24 * </div>
25 * <strong class="example">Example 2:
26 * <div class="example-block">
27 * Input: <span class="example-io">fruits = [3,6,1], baskets = [6,4,7]</span>
28 * Output: <span class="example-io">0</span>
29 * Explanation:
30 * 
31 * 	fruits[0] = 3 is placed in baskets[0] = 6.
32 * 	fruits[1] = 6 cannot be placed in baskets[1] = 4 (insufficient capacity) but can be placed in the next available basket, baskets[2] = 7.
33 * 	fruits[2] = 1 is placed in baskets[1] = 4.
34 * 
35 * Since all fruits are successfully placed, we return 0.
36 * </div>
37 *  
38 * Constraints:
39 * 
40 * 	n == fruits.length == baskets.length
41 * 	1 <= n <= 100
42 * 	1 <= fruits[i], baskets[i] <= 1000
43 * 
44 */
45pub struct Solution {}
46
47// problem: https://leetcode.com/problems/fruits-into-baskets-ii/
48// discuss: https://leetcode.com/problems/fruits-into-baskets-ii/discuss/?currentPage=1&orderBy=most_votes&query=
49
50// submission codes start here
51
52impl Solution {
53    pub fn num_of_unplaced_fruits(fruits: Vec<i32>, baskets: Vec<i32>) -> i32 {
54        0
55    }
56}
57
58// submission codes end
59
60#[cfg(test)]
61mod tests {
62    use super::*;
63
64    #[test]
65    fn test_3477() {
66    }
67}
68

Back
© 2026 bowen.ge All Rights Reserved.