FastPrepCoin Change II

Coin Change II

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREENONSITE INTERVIEW
Learn

Problem statement

Given distinct positive denominations coins and a nonnegative amount, return the number of unordered combinations that sum exactly to amount.

You may use each denomination any number of times. Different orders of the same multiset count once.

Function

countCoinChangeCombinations(coins: int[], amount: int) → long

Examples

Example 1

coins = [1,2,5]amount = 5return = 4

The combinations are 5; 2+2+1; 2+1+1+1; and five 1s.

Example 2

coins = [2]amount = 3return = 0

No number of 2s sums to 3.

Constraints

  • 1 <= coins.length <= 100.
  • 1 <= coins[i] <= 5000 and denominations are distinct.
  • 0 <= amount <= 5000.
  • The answer fits in a signed 64-bit integer.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public long countCoinChangeCombinations(int[] coins, int amount) {
  // Write your code here.
}
coins[1,2,5]
amount5
expected4
Checking account…