Coin Change
Problem Statement
You are given coins of several values and a total amount. You have an unlimited supply of every coin.
Find the fewest coins that add up to exactly amount. If no mix of the coins can make amount, return -1.
coins, a list of coin values, and amount, the total you want to make.
The fewest number of coins that add up to amount, or -1 if the amount cannot be made.
11 = 5 + 5 + 1. No other mix uses fewer than three coins.
Only 2s are available, and 3 is odd, so 3 cannot be made.
The amount is 0, so no coins are needed.
- • 1 ≤ coins.length ≤ 12
- • 1 ≤ coins[i] ≤ 2^31 − 1
- • 0 ≤ amount ≤ 10^4
Pattern Recognition Clues
Recognising these key signals in the problem description immediately identifies the pattern:
Approach Complexity Ladder
Recurse on the amount left for every coin that fits; no memory
dp[a] = fewest coins for each amount, filled from 0 up; one min per coin
To make a, try every coin that fits in a. For each coin, find the fewest coins for a − coin with the same method, then add one coin. Keep the smallest result. An amount of 0 costs 0 coins.
Recognition rule for this sub-pattern:
Unlock Complete Visual Walkthrough & Optimal C++
The interactive animated dry-run player, optimized C++ implementation, state invariant derivations, and edge-case breakdown for this question are part of Brute2Best Pro. The anchor question of every sub-pattern is completely free.
First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.
How this concept connects to System Design & C++ Systems
Top engineering interviews test whether you understand how algorithms like DP — Knapsack translate into production architectures and low-level memory mechanics.
Foundations: Object-Oriented Principles in C++23
Class invariants, pure virtual interfaces, and RAII smart pointers.
Food Delivery System (Zomato Architecture)
Real-world machine coding application of algorithms and design patterns.
Pointers vs References Deep Dive
Pointer arithmetic and memory layout under the hood.
Virtual Method Table (vtable) & Memory Layout
Polymorphism, vptr overhead, and multiple inheritance in memory.