FastPrepCount Coin Change Combinations
Problems/Count Coin Change Combinations

Count Coin Change Combinations

Datadog logoDatadog● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The firsthand report identifies a variation of Coin Change II but does not preserve its variation details. This exercise practices the named combination-counting core. Unlimited supply, ordering, zero and empty cases, interface, and bounds are specified for practice. The core task matches the report at about 75%.

Count the distinct combinations of coins whose values sum to amount. Every denomination in coins is available in unlimited quantity. Two combinations differ only when some denomination is used a different number of times; coin order does not matter.

Return the number of combinations as a 64-bit integer. Amount zero has one combination, choosing no coins. If a positive amount cannot be made, return zero. With no denominations, only amount zero can be made.

Function

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

Examples

Example 1

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

The four combinations are 5, 2+2+1, 2+1+1+1, and 1+1+1+1+1. Reordering the same coins does not produce a new combination.

Example 2

coins = [2]amount = 3return = 0

Any number of value-2 coins has an even sum, so none totals 3.

Example 3

coins = []amount = 0return = 1

There is exactly one combination for amount zero: choose no coins. It remains valid when no denominations are available.

Constraints

  • 0 <= coins.length <= 20
  • 1 <= coins[i] <= 100
  • The denominations are strictly increasing.
  • 0 <= amount <= 50

More Datadog problems

  • Query Log MatchPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Delete a Filesystem TreePHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Grouped-Query Attention Forward PassPHONE SCREEN · Seen Jun 2026
All Datadog interview questionsSee Datadog hiring insights
Saved
public long countCoinCombinations(int[] coins, int amount) {
    // Write your code here.
}
Checking account…