All challenges
Medium 0 solved 0% acceptance

Count Coin Combinations

Count ways to make an amount with unlimited coins of specified denominations.

Problem

Use any number of each supplied denomination to make amount exactly. Count combinations, not orderings: two arrangements using the same counts of each coin are the same way. Denominations are distinct and positive.

Implement coin_sums(amount, coins).

Input

amount: The total amount to make.

coins: The available distinct denominations.

Output

Return the number of unordered combinations.

Constraints

0 ≤ amount ≤ 200. There are 0 through 10 distinct denominations, each from 1 through 200. All counts fit signed 64-bit. Amount 0 has one way: choose no coins.

Examples

Example 1
Input:
coins = [1, 2]
amount = 4

Expected output:
expected = 3
Input:
std::vector<long long> coins = {1, 2};
long long amount = 4;

Expected output:
long long expected = 3;
Input:
long[] coins = new long[] {1, 2};
long amount = 4;

Expected output:
long expected = 3;

Explanation

The combinations are four 1s, two 1s with one 2, and two 2s.

Example 2
Input:
coins = [2]
amount = 3

Expected output:
expected = 0
Input:
std::vector<long long> coins = {2};
long long amount = 3;

Expected output:
long long expected = 0;
Input:
long[] coins = new long[] {2};
long amount = 3;

Expected output:
long expected = 0;

Explanation

Any sum of 2-valued coins is even, so 3 is impossible.

References

This challenge is adapted for CodeUtility. Follow the statement and constraints above.

Learn from others

Community solutions

No published solutions yet. Solve this challenge to share the first one.