Skip to content
Onsite

Climbing Stairs With 1, 2 or 3 Steps

EasyP1Coding

Count the number of distinct ways to climb a staircase of n steps when each hop can be 1, 2 or 3 steps. Different orders count as different ways: 1 + 2 and 2 + 1 are two ways to climb 3 steps.

There is exactly one way to climb 0 steps (do nothing).

Example 1

Input
n = 3
Output
4
Why
1+1+1, 1+2, 2+1 and 3.

Example 2

Input
n = 4
Output
7

Example 3

Input
n = 0
Output
1

Constraints

  • 0 <= n <= 30

Hints

Run checks the 3 visible tests, Submit all 10.