Back to exercises

Coin Change

Initialize a DP array with an impossible sentinel value, set dp[0] to zero, and for each amount try every coin to update the cheapest reachable solution.

Coding Exercises Medium O(amount * len(coins))

Coin Change

Initialize a DP array with an impossible sentinel value, set dp[0] to zero, and for each amount try every coin to update the cheapest reachable solution.

Given coin denominations and a target amount, return the minimum number of coins needed to make that amount or -1 if it is impossible.