Algorithms Playbook
← All problems
Easy1D dynamic programming →Similar to: Climbing Stairs

Ways up the stairs

Problem

You climb a staircase with n steps. Each move is 1 or 2 steps. In how many distinct sequences of moves can you reach the top?

Examples

Input: n = 3

Output: 3

1+1+1, 1+2, 2+1.

Input: n = 5

Output: 8

Hints

    Try it first. Every hint reveals a bit more.

    Solution