title: dynamic programming coin change that return an array
body: <p>I am trying to get all the coins that are the sum of target amount. I was able to get the amount of coins needed. How would i go about solving it. </p>
  
  <p>You can use the same coins unlimited 
  eg. <code>change([2], 10)</code> => <code>[2, 2, 2, 2, 2]</code></p>
  
  <pre><code>def change(coins, amount):
      result = [amount+1] * (amount+1)
  
      result[0] = 0
  
      for i in range(1, amount+1):
          for coin in coins:
              if i &gt;= coin:
                  result[i] = min(result[i], result[i-coin] + 1)
  
      if result[amount] == amount+1:
          return -1
  
      return result[amount]
  </code></pre>
  
  <p><code>change([1, 2, 5,8], 7)</code> => <code>[5, 2]</code> order does not matter.</p>