Coin change: greedy vs optimal
easyWith 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 DPLoading the coin change: greedy vs optimal engine…