Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare the memo map for caching results.
DSA Go
var memo = make(map[int]int[1])Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets [] instead of curly braces {}
Using parentheses () which is invalid for map initialization
✗ Incorrect
The memo map is initialized with curly braces {} to create an empty map.
2fill in blank
mediumComplete the code to check if the result for n is already cached in memo.
DSA Go
if val, ok := memo[[1]]; ok { return val }
Attempts:
3 left
💡 Hint
Common Mistakes
Checking memo[result] instead of memo[n]
Using memo[val] which is incorrect
✗ Incorrect
We check if the input n is already in the memo map to avoid recomputation.
3fill in blank
hardFix the error in the recursive call to fib by adding memoization.
DSA Go
memo[n] = fib([1], memo) + fib(n-2, memo)
Attempts:
3 left
💡 Hint
Common Mistakes
Using fib(n) causing infinite recursion
Using fib(n+1) which is incorrect
✗ Incorrect
The recursive call should be fib(n-1, memo) to compute the previous Fibonacci number.
4fill in blank
hardFill both blanks to complete the memoized Fibonacci function signature and base case check.
DSA Go
func fib([1] int, [2] map[int]int) int { if n <= 1 { return n }
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong parameter names like val or cache
Missing the memo parameter
✗ Incorrect
The function takes n as int and memo as map[int]int for caching.
5fill in blank
hardFill all three blanks to complete the memoized Fibonacci function body.
DSA Go
if val, ok := [1][n]; ok { return val } memo[n] = fib(n-1, [2]) + fib(n-2, [3]) return memo[n]
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names instead of memo
Not passing memo in recursive calls
✗ Incorrect
The memo map is used to check and store computed Fibonacci values.
