Let me show you how to add memoization to your Fibonacci function. You'll keep an array called dp to store computed values and initialize it to .
Before you recurse, you check if is . - If so, it means you haven't computed it yet. So, you compute the result as usual, store it in dp[n], then return it. - Otherwise, just return it.dp[n].
This way, every value of n is computed at most once. Memoization is a technique to avoid redundant computation. You store the result of each subproblem the first time you solve it. Later, if you need the same result, you look it up instead of recomputing it.