1798. Maximum Number of Consecutive Values You Can Make Medium

@problem@discussion
#Array#Greedy



1/**
2 * [1798] Maximum Number of Consecutive Values You Can Make
3 *
4 * You are given an integer array coins of length n which represents the n coins that you own. The value of the i^th coin is coins[i]. You can make some value x if you can choose some of your n coins such that their values sum up to x.
5 * Return the maximum number of consecutive integer values that you can make with your coins starting from and including 0.
6 * Note that you may have multiple coins of the same value.
7 *  
8 * Example 1:
9 * 
10 * Input: coins = [1,3]
11 * Output: 2
12 * Explanation: You can make the following values:
13 * - 0: take []
14 * - 1: take [1]
15 * You can make 2 consecutive integer values starting from 0.
16 * Example 2:
17 * 
18 * Input: coins = [1,1,1,4]
19 * Output: 8
20 * Explanation: You can make the following values:
21 * - 0: take []
22 * - 1: take [1]
23 * - 2: take [1,1]
24 * - 3: take [1,1,1]
25 * - 4: take [4]
26 * - 5: take [4,1]
27 * - 6: take [4,1,1]
28 * - 7: take [4,1,1,1]
29 * You can make 8 consecutive integer values starting from 0.
30 * Example 3:
31 * 
32 * Input: nums = [1,4,10,3,1]
33 * Output: 20
34 *  
35 * Constraints:
36 * 
37 * 	coins.length == n
38 * 	1 <= n <= 4 * 10^4
39 * 	1 <= coins[i] <= 4 * 10^4
40 * 
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/maximum-number-of-consecutive-values-you-can-make/
45// discuss: https://leetcode.com/problems/maximum-number-of-consecutive-values-you-can-make/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50    pub fn get_maximum_consecutive(coins: Vec<i32>) -> i32 {
51        0
52    }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59    use super::*;
60
61    #[test]
62    fn test_1798() {
63    }
64}
65


Back
© 2025 bowen.ge All Rights Reserved.