Complete the code to declare the memo array for storing computed Fibonacci values.
int memo[[1]];The memo array size should be large enough to store Fibonacci values up to the maximum input. 1000 is a common safe size.
Complete the code to initialize the memo array with -1 to indicate uncomputed values.
for (int i = 0; i < n; i++) { memo[i] = [1]; }
We use -1 to mark that the Fibonacci value for that index is not computed yet.
Fix the error in the memoization check to return the stored value if already computed.
if (memo[n] != [1]) { return memo[n]; }
We check if memo[n] is not -1, meaning it is already computed, so we return it directly.
Fill both blanks to complete the recursive Fibonacci function with memoization.
int fib(int n) {
if (n <= 1) return n;
if (memo[n] != -1) return memo[n];
memo[n] = fib(n [1] 1) + fib(n [2] 2);
return memo[n];
}We calculate fib(n-1) and fib(n-2) and add them to get fib(n).
Fill all three blanks to complete the memoization initialization and function call.
for (int i = 0; i < [1]; i++) { memo[i] = [2]; } int result = fib([3]);
Initialize memo for all n elements with -1, then call fib(10) to compute the 10th Fibonacci number.