Solution #494 - Coin Change - 3/08/2025#81
Solution #494 - Coin Change - 3/08/2025#81Prababil wants to merge 6 commits intoDijkstra-Edu:masterfrom
Conversation
SSexpl
left a comment
There was a problem hiding this comment.
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.
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 - Mediumfolder toDPfoldercoin change.cppfile to#322 - Coin Change - MediumfolderExplanation.mdto#322 - Coin Change - Mediumfolder