Memoized Function - Problem
Implement a function with memoization to efficiently calculate the Nth Fibonacci number.
The Fibonacci sequence is defined as:
F(0) = 0F(1) = 1F(n) = F(n-1) + F(n-2)for n > 1
Your function should use memoization to store previously calculated values and avoid redundant computations.
Input: An integer n (0 ≤ n ≤ 100)
Output: The Nth Fibonacci number
Input & Output
Example 1 — Small Number
$
Input:
n = 5
›
Output:
5
💡 Note:
F(5) = F(4) + F(3) = 3 + 2 = 5. The sequence is: 0, 1, 1, 2, 3, 5
Example 2 — Base Case
$
Input:
n = 0
›
Output:
0
💡 Note:
F(0) = 0 by definition
Example 3 — Another Base Case
$
Input:
n = 1
›
Output:
1
💡 Note:
F(1) = 1 by definition
Constraints
- 0 ≤ n ≤ 100
- Result fits in 64-bit integer
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code