You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Your solutions are excellent and demonstrate a good understanding of dynamic programming. You have provided multiple approaches, which is great. Here are some suggestions for improvement:
In the first solution, consider renaming tempR and tempB to something more descriptive like prevR and prevB to indicate that they are storing the previous values. This will make the code easier to follow.
You might want to uncomment the recursive solution if you intend to show it, but note that for this problem the iterative solutions are preferred due to their efficiency and avoiding recursion overhead.
The first solution is the best in terms of space complexity, so you could highlight that as the optimal solution.
Overall, your code is correct, efficient, and well-written. Keep up the good work!
VERDICT: PASS
Coin Change II (coin-change-2.py)
Your submission shows good understanding of multiple approaches to this problem. However, there are some critical issues:
DP Solutions (1D and 2D): These implementations are incorrect because they count permutations rather than combinations. For the coin change problem (where order doesn't matter), you need to process coins in a specific order. The standard approach is to iterate through coins first, then through amounts from the coin value up to the target amount. This ensures you're counting combinations rather than permutations.
Recursive Solution: This is correct! Good job on implementing the memoization. However, you could improve the code quality:
Use more descriptive variable names (e.g., skip_current instead of case1, take_current instead of case2)
Add comments explaining the two choices at each step
Consider making the memoization table a dictionary or using functools.lru_cache for cleaner code
Overall: You demonstrated knowledge of multiple techniques, but need to be more careful about the fundamental difference between counting combinations vs permutations in dynamic programming problems.
VERDICT: NEEDS_IMPROVEMENT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.