Skip to main content
← Problem catalogue Understand the pattern. Try it yourself. Review the solution. Practice this pattern →
Medium Dynamic Programming High frequency Solution Available Practice Mode

Coin Change LeetCode Solution

Tags: #Array #DP #BFS

Approach Summary

dp[i] = min coins to make amount i. For each amount, try all coins: dp[i] = min(dp[i], dp[i - coin] + 1).

Practice Mode 2 Progressive Approaches

Solve it yourself before revealing the code

DSA interviews test reasoning from brute force to optimal. Think through the constraints first.

Algorithmic Pattern

Master the Dynamic Programming Pattern

View Pattern Guide →

Study the core invariant, step-by-step decision framework, and common interview traps for the Dynamic Programming pattern.

Framework: Dynamic Programming • Interview Prep: Tested at FAANG • Explore all Dynamic Programming problems & invariants →

How to Recognize This Pattern

  • Minimum coins to make amount
  • Unbounded knapsack

Complexity Analysis

Time Complexity

O(amount × n)

Space Complexity

O(amount)

Tags

Array DP BFS

Frequently Asked Questions

What is the optimal time and space complexity for Coin Change?
The optimal solution for Coin Change achieves O(amount × n) runtime complexity and requires O(amount) auxiliary space. Time complexity is O(amount * n) where n is the number of coins, as we evaluate every coin for each sub-amount from 1 to amount. Space complexity is O(amount) for the 1D DP table.
How do I identify that Coin Change requires the Dynamic Programming pattern?
In technical interviews, look for key problem signals: Minimum coins to make amount; Unbounded knapsack. Recognizing these invariants allows you to bypass naive brute-force exhaustive search in favor of Dynamic Programming strategy.
What critical edge cases must be handled in Coin Change?
Essential edge cases to verify include: amount = 0 (0 coins required; returns 0); No combination can make amount (e.g. coins = [2], amount = 3; returns -1); Coins larger than amount (e.g. coins = [5], amount = 3; skipped during loop); Coin denominations not sorted (unbounded DP handles any order correctly). Always walk through these scenarios with your interviewer before coding.
Which tech companies frequently ask Coin Change?
Coin Change is a Medium-difficulty question tagged with high recurrence. It is actively asked in technical screening and onsite interview loops at Amazon, Google, Microsoft, Goldman Sachs.
Buy me a coffee
Daily Practice
0/0