Complete the code to initialize the DP table with zeros.
dp := make([]int, [1])We create a DP table of size n+1 to include the base case at index 0.
Complete the code to fill the DP table bottom-up for the Fibonacci sequence.
for i := 2; i <= n; i++ { dp[i] = dp[i-1] [1] dp[i-2] }
Fibonacci numbers are the sum of the two previous numbers.
Fix the error in the loop condition to avoid index out of range.
for i := 2; i < [1]; i++ { dp[i] = dp[i-1] + dp[i-2] }
The loop must run until i equals n inclusive, so use n+1.
Fill both blanks to create a DP table for the coin change problem counting ways.
dp := make([]int, [1]) dp[0] = [2]
The DP table size is amount+1 to include zero amount, and dp[0] = 1 as base case.
Fill all three blanks to complete the nested loops for the coin change problem.
for _, coin := range coins { for x := [1]; x <= [2]; x++ { if x >= coin { dp[x] += dp[x-[3]] } } }
The inner loop starts from coin value to amount, and dp[x] adds dp[x-coin].
