Fibonacci Number — Java Coding Problem
Difficulty: easy | Category: dynamic-programming
Problem Description
The **Fibonacci numbers** form a sequence: `F(0) = 0`, `F(1) = 1`, and `F(n) = F(n - 1) + F(n - 2)` for `n > 1`. Given `n`, compute `F(n)`. Hint: For efficiency, use bottom-up DP — just two variables are enough instead of recursion or a full array.
Examples
Example 1
Input: n = 2
Output: 1
Explanation: F(2) = F(1) + F(0) = 1 + 0 = 1.
Example 2
Input: n = 3
Output: 2
Explanation: F(3) = F(2) + F(1) = 1 + 1 = 2.
Example 3
Input: n = 10
Output: 55