Coins 1, 4, 5 — make 8. But this is wrong! #programming #coding #dynamicprogramming #greedy
Coins worth 1, 4 and 5. Make 8.
Biggest coin first gives you 5 + 1 + 1 + 1. It feels right
because it works for real money in almost every country in the world.
But 4 + 4 gets there in two.
Greedy commits to the five and never looks back. Dynamic programming tries both choices and keeps the better one.
That's the whole reason DP exists: when the obvious move can lock you
out of the best answer.
▸ The 5 patterns that cover most DP interview questions:
https://www.youtube.com/watch?v=rRRFvQezcSM
▸ Full dynamic programming course:
https://techwithnikola.com/course/dynamic-programming?utm_source=youtube&utm_medium=short_desc&utm_campaign=dp_founders_launch&utm_content=greedy_trap_short
#dynamicprogramming #leetcode #codinginterview #algorithms