·
·
·
·
·
·
·
Why greedy fails
▸1// greedy: always take the largest coin that fits2// coins [1, 3, 4], amount 6 → 4 + 1 + 1 = 3 coins3// but optimal is 3 + 3 = 2 coins → greedy is wrong
state
- coins[1, 2, 5]
- amount6
- greedy ideatake largest coin first