Done dp-2#1799
Conversation
Paint House (problem1.java)Your solution is excellent! You correctly identified the overlapping subproblems and applied dynamic programming to reduce the time complexity from exponential (in the recursive brute-force) to linear. Your code is clear and well-commented, which makes it easy to understand. Strengths:
Areas for Improvement:
Example of space-optimized solution (for your reference): Overall, great job! Your solution is efficient and correct. VERDICT: PASS Coin Change II (problem2.java)Your solution has a good intention to use dynamic programming with a 1D array to optimize space. However, there are a few critical issues:
To fix your code:
Here is a corrected version of your code: class Solution {
public int change(int amount, int[] coins) {
int[] dp = new int[amount + 1];
dp[0] = 1;
for (int coin : coins) {
for (int j = coin; j <= amount; j++) {
dp[j] += dp[j - coin];
}
}
return dp[amount];
}
}This solution is efficient and correct. VERDICT: NEEDS_IMPROVEMENT |
No description provided.