# Coin Change 1 \[Leetcode 322]

Problem Link: <https://leetcode.com/problems/coin-change/>

```python
class Solution:
    def coinChange(self, coins: List[int], amount: int) -> int:
         
        def tabulation(coins,amount,n):
              
            dp=[[0 for i in range(amount+1)] for j in range(n+1)]
            for i in range(n+1):
                for j in range(amount+1):
                    if(i==0):
                        dp[i][j]=9999999999
                    if(j==0):
                        dp[i][j]=0
                    if(i==1):
                        if(j%coins[i-1]==0):
                            dp[i][j]=j//coins[i-1]
                        else:
                            dp[i][j]=9999999999
                    else:
                        if(coins[i-1]<=j):
                            inc=1+dp[i][j-coins[i-1]]
                            exc=dp[i-1][j]
                            dp[i][j]=min(inc,exc)
                        else:
                            dp[i][j]=dp[i-1][j]
            return dp[n][amount]
            
             
        n=len(coins)
        ans = tabulation(coins,amount,n)
        if(ans==9999999999):
            return -1
        else:
            return ans
```
