AlgoFrames

Fibonacci with a table

Warm-up · Write code · about 5 min

Return fib(n), where fib(0) = 0, fib(1) = 1 and fib(i) = fib(i - 1) + fib(i - 2).

Fill a table from index 0 upward. Do not use recursion.

Example 1

Input:

[5]

Output:

5

Example 2

Input:

[10]

Output:

55

The table ends 34, 55.

Constraints

  • 0 ≤ n ≤ 40

Learn the idea first: Tabulation: filling the table bottom-up, a visual lesson.

More Tabulation: filling the table bottom-up problems