We could define memo[] to store the number of ways to ith step, it helps pruning recursion. And the recursive function could be defined as climb_Stairs(int i, int n, int memo[]) that returns the number of ways from ith step to nth step.

Complexity Analysis

Time complexity : O(n). Single loop upto n.

Space complexity : O(n). dpdp array of size n is used.

DP - Fibonacci Number - Optimize Space Complexity

Fib(n)=Fib(n−1)+Fib(n−2)

That the nth number only has to do with its previous two numbers, thus we don't have to maintain a whole array of results, just the last 2 results are enough. Thus optimized the space for O(1).