Imagine you're running a small coin exchange and want to know the maximum range of consecutive values you can make starting from 0 using your available coins.
You are given an integer array coins of length n representing the coins you own. The value of the i-th coin is coins[i]. You can make some value x if you can choose any subset of your coins such that their values sum up to x.
Goal: Return the maximum number of consecutive integer values that you can make with your coins starting from and including 0.
Note: You may have multiple coins of the same value, and you don't need to use all coins to make a value.
Example: If you have coins [1, 3], you can make values: 0 (no coins), 1 (coin 1), 3 (coin 3), and 4 (coins 1+3). Since you can make 0, 1 but not 2, the answer is 2.
Input & Output
Constraints
- 1 โค coins.length โค 4 ร 104
- 1 โค coins[i] โค 4 ร 104
- Each coin has a positive integer value