Climbing Stairs
Learn Climbing Stairs (Dynamic Programming, Advanced DSA) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
How Many Ways to Climb N Stairs, 1 or 2 Steps at a Time? The number of ways to reach step n equals ways to reach n-1 (then take 1 step) PLUS ways to reach n-2 (then take 2 steps) - literally the Fibonacci recurrence in disguise. Bottom-up DP builds this from the base cases upward, O(n) time, O(1) space.
More lessons in Dynamic Programming
- Fibonacci (DP)
- House Robber
- Kadane (DP)
- Grid Paths
- Unique Paths
- Minimum Path Sum
- 0/1 Knapsack
- Unbounded Knapsack
- Bounded Knapsack
- Subset Sum
- Equal Partition
- Target Sum
- Longest Common Subsequence - LCS
- Longest Common Substring
- Edit Distance
- Longest Palindromic Subsequence
- Palindrome Partitioning
- Longest Increasing Subsequence - LIS
- Number of LIS
- Maximum Sum Increasing Subsequence
- Matrix Chain Multiplication
- Burst Balloons
- Optimal BST
- Diameter (Tree DP)
- Maximum Path Sum (Tree DP)
- Tree Independent Set
- Traveling Salesman Problem
- Assignment Problems
- Counting Numbers (Digit DP)
- Digit Constraints