-
Notifications
You must be signed in to change notification settings - Fork 20
Solution #494 - Coin Change - 3/08/2025 #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great solution overall would be better if you can mention as to why Greedy Algorithm will fail in the scenario
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Looks almost good to me.
However, I have a few suggestions:
-
It's always good to start with the brute-force approach (plain recursion). Even if it's not optimal, it helps readers understand the problem-solving journey and why memoization or tabulation is needed later.
-
Please add your intuition how you approached the problem initially and what made you choose the current solution.
-
You’ve mentioned the time complexity, which is great! However, it would be helpful to explain why the time complexity is
O(n * t)
, where n is the number of coins and t is the target amount. For example:
We loop through each coin (n) and for each sub-amount from 0 to t, we compute the minimum coins required, leading toO(n * t)
complexity. -
The filename should match the function name for consistency.
In this case, please rename the file to: coinChange.cpp instead of a generic name. -
If you're comfortable with Java, Python, or C, feel free to add those implementations as well.
-
Please follow this PR naming format:
Solution #494 - Coin Change - dd/mm/yyyy -
Always create a feature branch for your PRs instead of working directly on main or master.
You can use this format :
feature/coin-change-solution
Yeah also mention this why going to DP or recursive approach is needed. |
I have modified the explanation to include the brute force approach as well as an explanation on why greedy algorithms will fail along with c, python and java solutions. Please review. |
@AbdulWahab938 @Prababil General observation, there's no need to add solutions from all the languages, especially for Vatsal, as he's new to DSA. Try to get good at one language, and then proceed with other solutions |
Summary
This PR adds cpp solutions for the coin change problem with 4 approaches along with explanation.
Changes
#322 - Coin Change - Medium
folder toDP
foldercoin change.cpp
file to#322 - Coin Change - Medium
folderExplanation.md
to#322 - Coin Change - Medium
folder