Posts

Coin change problem solution in clojure

Coin Change in Clojure: A Functional Take on Classic DP Dynamic Programming · Clojure · Loop/Recur · Persistent Data Structures The Coin Change problem is one of those classic puzzles that appears deceptively simple on the surface but exposes fundamental ideas about optimal substructure, overlapping subproblems, and the trade-offs between top-down (memoization) and bottom-up (tabulation) approaches. In this post we walk through a clean, idiomatic Clojure solution and highlight what makes it distinctly Lispy . Problem Statement Given an integer array coins representing coin denominations and an integer amount , return the fewest number of coins needed to reach exactly that amount. If no combination can reach it, return -1 . Example: coins = [1, 5, 6, 9] , amount = 11 Optimal: 9 + 1 + 1 = 11 → 3 coins . A greedy approach (take the largest coin first) would give 9 + 1 + 1 — that's lucky here, but ...