Fibonacci Sequence (Nth Term)
Hard
recursion
algorithms
dynamic_programming
Description
Find the nth term of the Fibonacci sequence, where F(0)=0 and F(1)=1. Optimize for performance using iteration or memoization to avoid redundant calculations.
Examples
Example:
Input: n = 7
Output: 13
Explanation: Sequence: 0, 1, 1, 2, 3, 5, 8, **13** (7th term, 0-indexed).
Constraints
- Input n is a non-negative integer (n must be between 0 and 30, inclusive, to prevent overflow).
- The solution must be efficient (avoid simple recursion with a running time proportional to 2^n).
Loading...
Test Case 1
Input: 0
Output: 0
Test Case 2
Input: 1
Output: 1
Test Case 3
Input: 7
Output: 13
Test Case 4
Input: 10
Output: 55
