Competitive ProgrammingEasy

Count ways to reach nth stair

Detailed guide and Python implementation for the 'Count ways to reach nth stair' problem.

Problem Statement

Easy

Write a function count_ways_stair(n) that returns the number of distinct ways to climb n stairs. Each time you can either climb 1 or 2 steps.

Constraints
  • 1 <= n <= 50

Examples

Example 1
Input
count_ways_stair(3)
Output
3
Explanation

There are three ways: 1+1+1, 1+2, and 2+1.

Example 2
Input
count_ways_stair(4)
Output
5
Explanation

There are five ways: 1+1+1+1, 1+1+2, 1+2+1, 2+1+1, 2+2.

Need a Hint?
Consider using Dynamic Programming-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor

Recommended Python Resources

Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.