3861. Minimum Capacity Box Easy

@problem@discussion
#Array



1/**
2 * [3861] Minimum Capacity Box
3 *
4 * You are given an integer array capacity, where capacity[i] represents the capacity of the i^th box, and an integer itemSize representing the size of an item.
5 * The i^th box can store the item if capacity[i] >= itemSize.
6 * Return an integer denoting the index of the box with the minimum capacity that can store the item. If multiple such boxes exist, return the smallest index.
7 * If no box can store the item, return -1.
8 *  
9 * <strong class="example">Example 1:
10 * <div class="example-block">
11 * Input: <span class="example-io">capacity = [1,5,3,7], itemSize = 3</span>
12 * Output: <span class="example-io">2</span>
13 * Explanation:
14 * The box at index 2 has a capacity of 3, which is the minimum capacity that can store the item. Thus, the answer is 2.
15 * </div>
16 * <strong class="example">Example 2:
17 * <div class="example-block">
18 * Input: <span class="example-io">capacity = [3,5,4,3], itemSize = 2</span>
19 * Output: <span class="example-io">0</span>
20 * Explanation:
21 * The minimum capacity that can store the item is 3, and it appears at indices 0 and 3. Thus, the answer is 0.
22 * </div>
23 * <strong class="example">Example 3:
24 * <div class="example-block">
25 * Input: <span class="example-io">capacity = [4], itemSize = 5</span>
26 * Output: <span class="example-io">-1</span>
27 * Explanation:
28 * No box has enough capacity to store the item, so the answer is -1.
29 * </div>
30 *  
31 * Constraints:
32 * 
33 * 	1 <= capacity.length <= 100
34 * 	1 <= capacity[i] <= 100
35 * 	1 <= itemSize <= 100
36 * 
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/minimum-capacity-box/
41// discuss: https://leetcode.com/problems/minimum-capacity-box/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46    pub fn minimum_index(capacity: Vec<i32>, item_size: i32) -> i32 {
47        0
48    }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55    use super::*;
56
57    #[test]
58    fn test_3861() {
59    }
60}
61

Back
© 2026 bowen.ge All Rights Reserved.