Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the ways array with the correct size.
DSA Go
ways := make([]int, [1])Attempts:
3 left
💡 Hint
Common Mistakes
Using amount instead of amount + 1 causes index out of range errors.
Using length of coins instead of amount + 1.
✗ Incorrect
The ways array should have a length of amount + 1 to include zero amount index.
2fill in blank
mediumComplete the code to set the base case for amount 0.
DSA Go
ways[0] = [1]
Attempts:
3 left
💡 Hint
Common Mistakes
Setting ways[0] to 0 means no ways to make amount 0, which is incorrect.
✗ Incorrect
There is exactly one way to make amount 0: by choosing no coins.
3fill in blank
hardFix the error in the inner loop condition to correctly update ways.
DSA Go
for j := coin; j [1] amount + 1; j++ { ways[j] += ways[j - coin] }
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= causes index out of range error.
Using > or >= causes the loop to not run correctly.
✗ Incorrect
The loop should run while j is less than amount + 1 to avoid index out of range.
4fill in blank
hardFill both blanks to complete the function signature and return statement.
DSA Go
func [1](coins []int, amount int) int { // function body return ways[[2]] }
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing 'ways' or 'coins' for the index in ways[index].
Using incorrect function name.
✗ Incorrect
The function is named coinChangeWays and returns ways[amount], the value in the ways array for the target amount.
5fill in blank
hardFill all three blanks to complete the nested loops for updating ways.
DSA Go
for _, [1] := range coins { for [2] := coin; [2] [3] amount + 1; [2]++ { ways[[2]] += ways[[2] - coin] } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using i instead of coin in outer loop.
Using >= instead of < in inner loop condition.
✗ Incorrect
The outer loop variable is coin, inner loop variable is j, and loop runs while j < amount + 1.
