you have m types of coins available in infinite quantities where the value of each coins is given in the array ss0 sm1 can you determine number of ways of making change for n units using the given types of coins https www hackerrank comchallengescoinchangeproblem dpcount1 2 3 4 4 dpcount1 2 3 7 8 dpcount2 5 3 6 10 5 dpcount10 99 0 dpcount4 5 6 0 1 dpcount1 2 3 5 0 tablei represents the number of ways to get to amount i there is exactly 1 way to get to zeroyou pick no coins pick all coins one by one and update table values after the index greater than or equal to the value of the picked coin dp_count 1 2 3 4 4 dp_count 1 2 3 7 8 dp_count 2 5 3 6 10 5 dp_count 10 99 0 dp_count 4 5 6 0 1 dp_count 1 2 3 5 0 table i represents the number of ways to get to amount i there is exactly 1 way to get to zero you pick no coins pick all coins one by one and update table values after the index greater than or equal to the value of the picked coin
def dp_count(s, n):
    
    if n < 0:
        return 0
    
    table = [0] * (n + 1)

    
    table[0] = 1

    
    
    
    for coin_val in s:
        for j in range(coin_val, n + 1):
            table[j] += table[j - coin_val]

    return table[n]


if __name__ == "__main__":
    import doctest

    doctest.testmod()