Skip to the code
cf.
+10 XP

#483 Stepper Click Paths

easy

A checkout page has a stepper with steps numbered 0 to n. You start on step 0. Each click on "Next" moves you forward 1 step, and each click on "Skip ahead" moves you forward 2 steps. You can never move past step n.

Write countClickPaths(n) that returns how many different click sequences take you from step 0 to exactly step n. Two sequences are different if they differ at any click.

Example 1

Input: n = 2
Output: 2

Next + Next, or one Skip ahead.

Example 2

Input: n = 4
Output: 5

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

Constraints

  • 1 <= n <= 45
  • The answer fits in a normal JavaScript number.
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).