forked from HarshCasper/NeoAlgo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstaircase_problem.py
More file actions
25 lines (20 loc) · 824 Bytes
/
staircase_problem.py
File metadata and controls
25 lines (20 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"""This program finds the total number of possible combinations that can be used to
climb statirs . EG : for 3 stairs ,combination and output will be 1,1,1 , 1,2 , 2,1 i.e 3 . """
def counting_stairs(stair_number):
result = stair_number
# This function uses Recursion.
if(stair_number <=1):
result = 1
else:
result = (counting_stairs(stair_number-1) + counting_stairs(stair_number-2))
return result
if __name__ == '__main__':
count_stair = int(input("Enter total number of stairs: "))
print(f"Total Number of possible Combinations = {counting_stairs(count_stair)}")
"""Output
Total Number of possible Combinations = 8
Enter total number of stairs: 5
Time Complexity : O(2^n)
Space Complexity :O(1)
Created by Shubham Patel on 16-12-2020 on WoC
"""