Grokking the Art of Recursion for Coding Interviews
Ask Author
Back to course home

0% completed

Vote For New Content
Caio Cutrim
Here the js function of tabulation approach

Caio Cutrim

Sep 27, 2024

// Function to compute the nth Fibonacci number function fibonacci(n) { // Create a table to store Fibonacci numbers let fibTable = new Array(n+1).fill(0); // Base cases fibTable[0] = 0; fibTable[1] = 1; // Fill fibTable in bottom-up manner for(let i = 2; i <= n; i++) { fibTable[i] = fibTable[i-1] + fibTable[i-2]; } // Return nth Fibonacci number return fibTable[n]; } let n = 13; console.log("Fibonacci number of " + n + " is " + fibonacci(n));

0

0

Comments
Comments

On this page