denominations, with an unlimited supply of each. You need to pay out exactly total.
Return the smallest number of bills that does it. If the exact sum cannot be made, return −1. When total is 0, the answer is 0.denominations=[4, 3, 10], total=13 → 2
13 = 10 + 3, so two bills are enough.
denominations=[6, 9], total=16 → -1
Any sum of 6s and 9s is divisible by 3, but 16 is not, so the answer is −1.
denominations=[1, 5, 6, 9], total=11 → 2
Greedily taking 9 + 1 + 1 uses three bills, while 6 + 5 needs only two.
denominations ≤ 12total ≤ 10⁴denominations=[4, 3, 10], total=13
2
Run checks the first 3 tests in your browser. Submit checks all 121 tests on the server, hidden ones included.