You are climbing a staircase with n steps. Each move you can climb either 1 or 2 steps. Return the number of distinct ways you can climb to the top.
n = 22n = 33Try it now — no sign-up needed. Write your solution in Python or JavaScript, run it against test cases, and submit for a verdict, right in your browser.
Open the editor →Break a problem into overlapping subproblems along a single dimension — like "the answer up to index i" — solve each one once, and reuse the result instead of recomputing it.
Read the full 1-D Dynamic Programming guide →
Original problem on LeetCode ↗