Coin change: greedy vs optimal

easy

With coins 1, 3, 4 and a target of 6, greedy takes three coins where two suffice. Both answers are shown side by side, which is the fastest way to internalise when greedy is unsafe.

Best O(n log n) greedyWorst O(amount × coins) DPSpace O(amount) for the DP
Loading the coin change: greedy vs optimal engine…

Where to go next