Total Unique Ways To Make Change - Dynamic Programming (Coin Change 2 on LeetCode) @BackToBackSWE
Total Unique Ways To Make Change - Dynamic Programming (Coin Change 2 on LeetCode)  @BackToBackSWE
Uploaded January 2019 | Updated November 2026, 1 day ago
Free 5-Day Mini-Course: backtobackswe.com
Try Our Full Platform: backtobackswe.com/pricing
πŸ“Ή Intuitive Video Explanations
πŸƒ Run Code As You Learn
πŸ’Ύ Save Progress
❓New Unseen Questions
πŸ”Ž Get All Solutions


Question: You are given coins of different denominations and a total amount of money. Write a function to compute the number of combinations that make up that amount. You may assume that you have an infinite number of each kind of coin.

Examples:

1

Input: amount = 5, coins = [1, 2, 5]
Output: 4

5=5
5=2+2+1
5=2+1+1+1
5=1+1+1+1+1

2

Input: amount = 3, coins = [2]
Output: 0

Can't make change for this amount given the coins we have.


This problem is very similar to the 0 / 1 knapsack problem.

We will use a bottom up dynamic programming approach to build to our final answer.

We will consider the total ways to make change with just the 1st coin, with just the 1st and 2nd coin, with just the 1st, 2nd, and 3rd, coin, and so on...


Complexities

A is the amount to make change for.
n is the total denominations avaliable to us.

Time: O( A * n )
For each denomination we will be solving A subproblems. So for each of the n we will be doing A work, hence multiplication.

Space: O( A * n )
Hold the answer to all subproblems.


Note: We can do this in just O( A ) space but we did it this way for simplicity

++++++++++++++++++++++++++++++++++++++++++++++++++

HackerRank: youtube.com/channel/UCOf7UPMHBjAavgD0Qw5q5ww

Tuschar Roy: youtube.com/user/tusharroy2525

GeeksForGeeks: youtube.com/channel/UC0RhatS1pyxInC00YKjjBqQ

Jarvis Johnson: youtube.com/user/VSympathyV

Success In Tech: youtube.com/channel/UC-vYrOAmtrx9sBzJAf3x_xw
Total Unique Ways To Make Change - Dynamic Programming (Coin Change 2 on LeetCode)How I Got An Internship @ TwitterThe Dutch National Flag Problem (The Quicksort Band-Aid)Search A 2D Sorted Matrix - Fundamentals of Search Space ReductionHow To Permute A String - Generate All Permutations Of A StringMerge 2 Sorted Lists - A Fundamental Merge Sort Subroutine (Merge Two Sorted Lists on LeetCode)Count Total Unique Binary Search Trees - The nth Catalan Number (Dynamic Programming)Coding Interview | QuickSort Overview #shorts #datastructures #codinginterviewWhat is Hashing? | Hashtables Explained #datastructures #hashtableIntroducing Asymptotic NotationsImplement A Sudoku Solver - Sudoku Solving Backtracking Algorithm (Sudoku Solver on LeetCode)The IP Address Decomposition Problem - Compute All Valid IP Addresses From Raw IP String
Back To Back SWE |

Total Unique Ways To Make Change - Dynamic Programming ("Coin Change 2" on LeetCode)

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER