Skip to content

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Prababil
Copy link
Member

Summary

This PR adds cpp solutions for the coin change problem with 4 approaches along with explanation.

Changes

  • Adds #322 - Coin Change - Medium folder to DP folder
  • Adds coin change.cpp file to #322 - Coin Change - Medium folder
  • Adds Explanation.md to #322 - Coin Change - Medium folder

Copy link
Member

@SSexpl SSexpl left a 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

Copy link
Member

@AbdulWahab938 AbdulWahab938 left a 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 to O(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

@AbdulWahab938
Copy link
Member

Great solution overall would be better if you can mention as to why Greedy Algorithm will fail in the scenario

Yeah also mention this why going to DP or recursive approach is needed.

@Prababil
Copy link
Member Author

Prababil commented Aug 2, 2025

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.

@Prababil Prababil changed the title Feat: Added cpp solutions for Coin Change problem Solution #494 - Coin Change - 3/08/2025 Aug 10, 2025
@JRS296
Copy link
Member

JRS296 commented Aug 13, 2025

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants