Complete the code to initialize the memoization slice for Fibonacci calculation.
memo := make([]int, [1])The memo slice must have size n+1 to store Fibonacci values from 0 to n.
Complete the code to check if Fibonacci value is already computed.
if memo[[1]] != 0 { return memo[n] }
We check memo[n] to see if Fibonacci of n is already computed.
Fix the error in the recursive Fibonacci call to use memoization correctly.
memo[n] = fibMemo(n-1, memo) [1] fibMemo(n-2, memo)
Fibonacci numbers are summed from previous two values.
Fill both blanks to complete the base case check for Fibonacci.
if n [1] 0 || n [2] 1 { return n }
Base cases are when n is exactly 0 or 1.
Fill all three blanks to complete the memoized Fibonacci function.
func fibMemo(n int, memo []int) int {
if n [1] 0 || n [2] 1 {
return n
}
if memo[[3]] != 0 {
return memo[n]
}
memo[n] = fibMemo(n-1, memo) + fibMemo(n-2, memo)
return memo[n]
}Base cases check if n == 0 or n == 1, and memo[n] is checked for cached value.
