title: Why does the code give me wrong output for an amount? (Change making problem)
body: <p>I was trying to solve the coin change problem in which we have to find the minimum number of coins that add up to a specific amount.</p>
  <p>Here is the solution I came up with:</p>
  <pre><code>import sys
  denomination = [1,6,10]
  amount = 12
  
  def coin_change(amount,denomination):
      coins = 0
      ans = [0]*(amount+1)
      temp = sys.maxsize
      for i in range(len(ans)):
          for j in range(len(denomination)):
              if denomination[j] &lt;= i:
                  ans[i] = min(temp, ans[i-denomination[j]]) + 1
      return ans
  
  print(coin_change(amount,denomination))
  </code></pre>
  <p>The output is</p>
  <pre><code>[0, 1, 2, 3, 4, 5, 1, 2, 3, 4, 1, 2, 3].
  </code></pre>
  <p>Why is the last number in the output a 3 for the amount 12? I have gone through the code so many times, but I still don't understand why this happens. It gives 1 for the amount 6, so it should give 2 for the amount 12 instead of 3.</p>
  <p>What's wrong with my code?</p>