Mental Model
Find the smallest number of coins needed to make a target amount using given coin values. We build up solutions from smaller amounts to the target.
Analogy: Imagine you want to pay a certain amount using coins from your pocket. You try to use the fewest coins possible by checking all smaller amounts first and remembering the best way to pay them.
coins = [1, 3, 4] amount = 6 We create an array dp where dp[i] means minimum coins to make amount i: Index: 0 1 2 3 4 5 6 Value: 0 ? ? ? ? ? ? We fill dp from left to right using coins.
