Programming Concepts — Dynamic Programming
Dynamic programming is a technique for solving problems by breaking them down into simpler overlapping subproblems and storing solutions to avoid repeated calculations.
function fibonacci(n, memo = {}) {
if (n <= 1) return n;
if (memo[n]) return memo[n];
memo[n] = fibonacci(n-1, memo) + fibonacci(n-2, memo);
return memo[n];
}
console.log(fibonacci(6)); // Output: 8