fork download
  1. amntForWhichChangeIsToBeFound = 11
  2. coinsWeHaveUsingwhichChangeHastoBeFound = [1,2,5]
  3. LastcoinUsedToGetChangeArray = [0]*(amntForWhichChangeIsToBeFound+1)
  4. numberOfCoinsUsedForChange = [0]*(amntForWhichChangeIsToBeFound+1)
  5. coinCount = 11
  6. LastCoinUsedforChange = 1
  7. numberOfCoinsUsedForChange[9] = 3
  8. numberOfCoinsUsedForChange[10] = 2
  9. numberOfCoinsUsedForChange[6] = 2
  10.  
  11. for j in [c for c in coinsWeHaveUsingwhichChangeHastoBeFound if c<=amntForWhichChangeIsToBeFound]:
  12. if numberOfCoinsUsedForChange[amntForWhichChangeIsToBeFound - j] + 1 < coinCount:
  13. coinCount = numberOfCoinsUsedForChange[amntForWhichChangeIsToBeFound - j] + 1
  14. LastCoinUsedforChange = j
  15. numberOfCoinsUsedForChange[amntForWhichChangeIsToBeFound] = coinCount
  16. LastcoinUsedToGetChangeArray[amntForWhichChangeIsToBeFound] = LastCoinUsedforChange
  17. print (numberOfCoinsUsedForChange)
  18. print (LastcoinUsedToGetChangeArray)
Success #stdin #stdout 0.02s 8688KB
stdin
1
2
10
42
11
stdout
[0, 0, 0, 0, 0, 0, 2, 0, 0, 3, 2, 3]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]