Foundations
Linear Structures
Hashing
Array and String Patterns
Recursion, Search, and Sorting
Problem Solving Patterns
Algorithm Searching
Sorting Algorithms
Array Algorithms
Grid Algorithms
Linear Structure Algorithms
Hashing Algorithms
Recursion and Backtracking
Greedy Algorithms
Tree and Heap Algorithms
Graph Algorithms
Dynamic Programming Algorithms
String Algorithms
Math Algorithms
Keyboard ready
Space plays. Arrow keys step. R restarts.
LAB Coin Change Lab
Dynamic Programming
Problem shape
Intermediate
4
8
15
16
23
42
Core idea
Build answers for smaller amounts, then extend them with each coin.
Step 1 / 5
Problem shape
Dynamic Programming Intermediate
Coin Change
Welcome to the Coin Change algorithm lab. Build answers for smaller amounts, then extend them with each coin. Use it when: Use for minimum coins, number of ways, and unbounded choice problems. The time complexity is O(amount * coins), and the space complexity is O(amount). The pseudocode is: dp[0] = 0 for value from 1 to amount dp[value] = infinity for coin in coins dp[value] = min(dp[value], 1 + dp[value - coin]) As you practice, track the state that changes and the condition that makes the algorithm stop.
Time
O(amount * coins)
Space
O(amount)
Pseudocode
dp[0] = 0
for value from 1 to amount
dp[value] = infinity
for coin in coins
dp[value] = min(dp[value], 1 + dp[value - coin]) 1.0x