Skip to interview prep
Apexed
Problem list103 / 125

103. Coin Change: Count the Ways

MediumDynamic programming

Given coin denominations coins (unlimited supply of each) and an amount, return how many different combinations of coins add up to the amount. Combinations that use the same coins in a different order count once.

Example 1

Input: amount = 5, coins = [1, 2, 5]
Output: 4
Explanation: 5, 2+2+1, 2+1+1+1, 1+1+1+1+1

Constraints

  • 0 ≤ amount ≤ 5000
  • 1 ≤ coins.length ≤ 300
  • Denominations are distinct
  • The answer fits in a 32-bit signed integer

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 5 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Coin Change: Count the Ways — coding interview practice — Apexed