LeetCode

Fibo

Custom
November 20, 2025 · Recursion · Dynamic Programming

Problem

Return the n-th Fibonacci number. The sequence starts 0, 1 and every following number is the sum of the previous two: 0, 1, 1, 2, 3, 5, 8, 13, ....

Solution

The textbook recursive definition, translated directly to code:

const fibo = (n: number): number => {
  if (n <= 1) return n;

  return fibo(n - 1) + fibo(n - 2);
};

Complexity Analysis

Measure Complexity
Time Complexity O(2^n)
Space Complexity O(n)

Notes