Step 1: Initialize dp array with dp[0] = 0 and others as infinity (unreachable)
dp: [0, ∞, ∞, ∞, ∞, ∞, ∞]
Why: Base case: zero coins needed to make amount 0
Step 2: Calculate dp[1]: check coins 1,3,4; only coin 1 fits, dp[1] = dp[0] + 1 = 1
dp: [0, 1, ∞, ∞, ∞, ∞, ∞]
Why: Amount 1 can be made with one coin of 1
Step 3: Calculate dp[2]: check coins 1,3,4; only coin 1 fits, dp[2] = dp[1] + 1 = 2
dp: [0, 1, 2, ∞, ∞, ∞, ∞]
Why: Amount 2 can be made with two coins of 1
Step 4: Calculate dp[3]: check coins 1,3,4; coin 3 fits, dp[3] = min(dp[2]+1, dp[0]+1) = min(3,1) = 1
dp: [0, 1, 2, 1, ∞, ∞, ∞]
Why: Amount 3 can be made with one coin of 3
Step 5: Calculate dp[4]: check coins 1,3,4; coin 4 fits, dp[4] = min(dp[3]+1, dp[1]+1, dp[0]+1) = min(2,2,1) = 1
dp: [0, 1, 2, 1, 1, ∞, ∞]
Why: Amount 4 can be made with one coin of 4
Step 6: Calculate dp[5]: check coins 1,3,4; dp[5] = min(dp[4]+1, dp[2]+1, dp[1]+1) = min(2,3,2) = 2
dp: [0, 1, 2, 1, 1, 2, ∞]
Why: Amount 5 can be made with two coins (4+1 or 3+1+1)
Step 7: Calculate dp[6]: check coins 1,3,4; dp[6] = min(dp[5]+1, dp[3]+1, dp[2]+1) = min(3,2,3) = 2
dp: [0, 1, 2, 1, 1, 2, 2]
Why: Amount 6 can be made with two coins (3+3 or 4+1+1)
Result: dp: [0, 1, 2, 1, 1, 2, 2]
Minimum coins needed: 2