Dsa
Graphs Dfs
Easy
Staircase Paths
Imagine a staircase with n steps. You can climb either 1 or 2 steps at a time. Write a function to count how many distinct ways you can reach the top of the staircase (nth step).
Input Format:
- A single integer n (1 <= n <= 50) representing the number of steps.
Output Format:
- Output the number of distinct ways to reach the top.
Example:
Input:
4
Output:
5
Key concepts
graphdfscombinatorics
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now