Back to exercises

Climbing Stairs

Each position depends on the previous two positions, so keep only the last two counts and build forward iteratively.

Coding Exercises Easy O(n)

Climbing Stairs

Each position depends on the previous two positions, so keep only the last two counts and build forward iteratively.

Return how many distinct ways there are to reach the top if you can climb 1 or 2 steps at a time.