fib_memo(n, memo=None) that computes the nth Fibonacci number using recursion plus a memo dictionary to cache previously computed results, avoiding the exponential blow-up of plain recursive Fibonacci. It must remain recursive — do not rewrite it as an iterative loop.fib_memo(30)
832040
Runs instantly thanks to the cache, unlike naive recursion.
fib_memo(1)
1
Base case.
Use a mutable default sentinel: `memo=None`, then `if memo is None: memo = {}` inside the function.
Before recursing, check `if n in memo: return memo[n]`.
Store each computed result in memo before returning it.