Compute the n-th Fibonacci number in the sequence defined by the sum of the two previous terms.
Given a non-negative integer , return the -th Fibonacci number.
The Fibonacci sequence is defined as:
This is a classic warm-up problem for practicing iterative computation, recursion, and dynamic programming.
Example 1
Input
n = 2
Output
1
Explanation
F(2) = F(1) + F(0) = 1 + 0 = 1.
Example 2
Input
n = 5
Output
5
Explanation
The sequence starts 0, 1, 1, 2, 3, 5, so F(5) = 5.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.