Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Memoize an expensive lookup function

Python data engineering interview problem. Difficulty: intermediate. Pattern: Recursion. About 15 minutes. Part of the Pro drill bank.

An expensive lookup (here, a Fibonacci-style recurrence) is called with the same n many times. Memoization should make repeated calls cheap.

Return the nth Fibonacci-like value using memoization.

Requirements

  • Reuse previously computed values.
  • Base cases must be defined.

Constraints

  • n: a non-negative integer.
  • n = 0 and n = 1 are the usual bases.
  • Do not recompute the same n in a tree of calls.

Examples

Input: fib_memo(0) Output: 0 This input follows the stated rules and produces this output.

Topics: lakebench, python, decorators.

More Python interview questions · All interview problems · Learn data engineering

intermediate

Memoize an expensive lookup function

Interview-style drill: Write a decorator that caches a function's results by its arguments.

Return the nth Fibonacci-like value using memoization.