dp array is initialized with zeros, which incorrectly suggests zero coins needed for all amounts.
Step 2: Correct initialization needed
dp should be initialized with a large number (like INT_MAX) to represent unreachable states, then updated with minimum coins.
Final Answer:
dp array is not initialized with large values -> Option A
Quick Check:
Initialize dp with max values to find minimum [OK]
Hint: Initialize dp with large values, not zeros [OK]
Common Mistakes:
Setting dp to zero causes wrong minimum calculations
Not updating dp[i] with minimum of previous values
Incorrect loop ranges
5. Given coins = {2, 5, 10} and amount = 7, what is the minimum number of coins needed? If it is not possible, return -1. Use the Coin Change Minimum Coins logic.
hard
A. -1
B. 2
C. 3
D. 1
Solution
Step 1: Check possible combinations for amount 7
Coins are 2, 5, 10. Possible sums:
- 2+5=7 (2 coins)
- 5+2=7 (2 coins)
- 10 is too large
So minimum coins = 2.
Step 2: Confirm no smaller combination
Since 1-coin denominations are not available, 2 coins is minimum.
Final Answer:
2 -> Option B
Quick Check:
7 = 2 + 5, minimum coins = 2 [OK]
Hint: Try all coin combos to find minimum or detect impossibility [OK]
Common Mistakes:
Assuming 7 cannot be formed without 1-coin denomination
Returning -1 incorrectly
Ignoring order of coins
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.