Member-only story
Count Ways To Reach the nth stair 🤷🏻♀️ (Climbing 🧗🏼♂️ Stairs)| Python & CPP | DP | Coding Interview
This fundamental problem can show the use of DP in very simple terms. We will easily see why and how to implement a DP solution in this case. This problem has been asked by Amazon, Microsoft, Google, Bloomberg, Apple, and Adobe.
After discussing the brute force (recursive way), we will discuss both the bottom-up approach as well as a top-down approach.
This article belongs to the 30 Days Preparation Plan.
Contents
- Description
- Brute Force (Recursive)
- Solution (Top-down approach)
- Solution (Bottom-up approach)
- Time & Space Complexity
Description
We are climbing 🧗♂️ a staircase, and it takes n steps to reach the top. Give the number of ways we can reach the top if we can either climb 1 step or 2 steps.
Let’s say we have to climb 2 stairs in total; then we can get there by taking 2 one steps or by taking 1 two-step.