1117. Fibonacci Number (Bottom-Up DP)

EasyDynamic Programming1D DPFibonacci

The Fibonacci sequence is defined by F(0)=0, F(1)=1, and F(n)=F(n-1)+F(n-2) for n>=2. Given n, return F(n) using bottom-up dynamic programming. The input is JSON {n}.

Input: JSON {n}.

Output: Integer — the nth Fibonacci number.

Examples

Example 1
Input: {"n":10}
Output: 55
Explanation: F(10) = 55.
Example 2
Input: {"n":0}
Output: 0
Explanation: Base case.
Example 3
Input: {"n":1}
Output: 1
Explanation: Base case.

Constraints

Asked by

CognizantInfosysAccentureMicrosoftBloombergAmazon
Solve this problem in the editor →