Complete the code to declare the memo array for storing intermediate results.
int memo[[1]];The memo array size should be n+1 to store results for all states from 0 to n.
Complete the code to check if the result is already computed in memo.
if (memo[n] != [1]) return memo[n];
We initialize memo with -1 to indicate uncomputed states. So we check if memo[n] != -1.
Fix the error in the recursive call to compute the result for n-1.
int result = [1](n - 1, memo) + n;
The function name is 'solve' and should be called exactly as defined.
Fill both blanks to initialize memo and set base case value.
std::fill(memo, memo + [1], [2]); memo[0] = 0;
We fill memo with -1 for all n+1 elements to mark uncomputed states. Base case memo[0] is set to 0.
Fill all three blanks to complete the memoization function.
int solve(int n, int memo[]) {
if (n == 0) return 0;
if (memo[n] != [1]) return memo[n];
int result = solve(n [2] 1, memo) + n;
memo[n] = [3];
return memo[n];
}Check if memo[n] != -1, then call solve(n - 1, memo) + n, store result in memo[n].
