Intermediate·Concept·2 min read

Dynamic programming in JavaScript

Practice this question

Problems to practice

  • Climbing Stairs
  • House Robber
  • Coin Change
  • Unique Paths
  • Longest Increasing Subsequence
  • Word Break

Example: climbing stairs

JavaScript
function climbStairs(n) {
  const dp = new Array(n + 1).fill(0);
  dp[0] = 1;
  dp[1] = 1;

  for (let i = 2; i <= n; i++) {
    dp[i] = dp[i - 1] + dp[i - 2];
  }

  return dp[n];
}

Adapted from 16_DSA_JAVASCRIPT.md · “10. Dynamic programming in JavaScript”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.