LeetCode 279: Perfect Squares, Deriving Dynamic Programming from Remaining Sums

Problem Requirements Given a positive integer n, return the minimum number of positive perfect squares whose sum is exactly n. A perfect square is the square of an integer, such as 1 = 1², 4 = 2², 9 = 3², or 16 = 4². The sum must equal n exactly. You may use the same perfect square any number of times. Return only the count, not the decomposition. The order of the terms does not affect the answer. Constraint: 1 <= n <= 10^4. Input: n = 12 Output: 3 Explanation: 12 = 4 + 4 + 4 uses 3 perfect squares. Input: n = 13 Output: 2 Explanation: 13 = 9 + 4 uses 2 perfect squares. This guide builds the solution in Python 3.9+. It assumes familiarity with functions, loops, and basic recursion, and develops the dynamic programming reasoning step by step. ...

October 8, 2026 · 10 min · map[name:Jeanphilo]

LeetCode 322: Coin Change, Deriving Unbounded Knapsack DP from Smaller Amounts

Problem Requirements You are given an integer array coins, where coins[i] is a coin denomination, and a non-negative integer amount. The goal is to make a total exactly equal to amount. You may use each denomination any number of times. Return the minimum number of coins needed to make amount. If the amount cannot be made, return -1. If amount = 0, no coins are needed, so the answer is 0. The constraints are 1 <= coins.length <= 12, 1 <= coins[i] <= 2^31 - 1, and 0 <= amount <= 10^4. All coin denominations are distinct. ...

September 22, 2026 · 13 min · map[name:Jeanphilo]