stamps; several stamps may share a value. An amount x can be paid if some set of stamps (each stamp used at most once) adds up to exactly x. The amount 0 can always be paid with no stamps at all.
Return how many consecutive amounts starting from 0 can be paid, that is, the largest k such that every amount 0, 1, …, k - 1 is payable.stamps=[1, 2, 6] → 4
The sums 0, 1, 2 and 3 can be made (0 with no stamps, 3 = 1 + 2), but 4 cannot. The answer is 4.
stamps=[3, 1, 1] → 6
Every sum from 0 to 5 can be made, for example 4 = 3 + 1 and 5 = 3 + 1 + 1. That is 6 values.
stamps=[2] → 1
The sum 1 is out of reach, so only 0 counts.
stamps[i] ≤ 4 · 10⁴stamps=[1, 2, 6]
4
Run checks the first 3 tests in your browser. Submit checks all 94 tests on the server, hidden ones included.