2

Combination Sum

Given an array of distinct integer nums and a target integer target, return the number of possible combinations that add up to the target.

Input: nums = [1,2,3], target = 4 Output: 7 Explanation: The possible combination ways are: (1, 1, 1, 1) (1, 1, 2) (1, 2, 1) (1, 3) (2, 1, 1) (2, 2) (3, 1) Note that different sequences are counted as different combinations.

Coin Change

For the given infinite supply of coins of each of denominations, D = {D0, D1, D2, D3, ...... Dn-1}. You need to figure out the total number of ways W, in which you can make the change for Value V using coins of denominations D.

For the same Input as above question: Number of ways are - 4 total i.e. (1,1,1,1), (1,1, 2), (1, 3) and (2, 2).

I know how to solve Coin Change using the concept of UNBOUNDED KNAPSACK. But how Combination Sum IV is different here! Seems so similar

Evg
  • 25,259
  • 5
  • 41
  • 83
  • 1
    For one thing - One cares about sequence `order` (coin change), and the other does not. – Daniel Hao Jul 14 '22 at 10:10
  • This is not the coin change problem. It should return the fewest number of coins to get a number (if possible). – maraca Jul 14 '22 at 20:06
  • @maraca both are coin change problems, just different variations of it. – Will Ness Jul 16 '22 at 12:24
  • the main difference seems to be that order matters for the first problem. – maraca Jul 16 '22 at 14:39
  • So you could solve coin change and then add all unique permutations of the solution and you end up with combination sum. Or you could solve combination sum and then discard same permutations except 1 to get coin change. Hamiltonian cycle and path is also more or less the same and you can get one or the other by introducing a fake node, so if you can solve one you can solve the other. – maraca Jul 16 '22 at 15:47

0 Answers0