Classic DP: ways(n) = ways(n-1) + ways(n-2). Base cases 1 and 2.
def climbStairs(n): a=b=1 for _ in range(n): a,b=b,a+b return a
Affiliation: I work on Linkjob AI, a real-time interview helper. See the interview copilot.