Coin Change II

Dynamic Programming
Medium

Approach

Diagrams

Analysis

Time

O(mn)

Space

O(n)
class Solution:
    def change(self, amount, coins):
        dp = [0] * (amount + 1)
        dp[0] = 1
        
        for coin in coins:
            for amount in range(1, len(dp)):
                if amount - coin >= 0:
                    dp[amount] += dp[amount - coin]
                    
        return dp[-1]

Learn

#Dynamic Programming

#Ways

Videos