Skip to main content

Practice ยท 1 of 1

Memoized fib, counted

Implement fib(n, memo, stats) โ€” recursive Fibonacci with explicit memoization: - memo is a dict the function may read and write - stats is a dict containing 'calls'; increment stats['calls'] += 1 at the top of EVERY invocation (including memo-hit returns) - fib(0)=0, fib(1)=1, else fib(n-1)+fib(n-2) The graded test calls fib(25, {}, stats) and asserts the value is 75025 and stats['calls'] is under 60 (the never-reads-memo version makes ~243k calls).

Difficulty: advanced

Back to lesson: Practice: Memoization Practice