Combinations to reach the top of the stairs

Question

Suppose you're at the bottom of a staircase with S steps. You're told you can climb up some number of stairs at a time as defined by an array of positive integers, C. For example, if C = [1,3] then you could climb the stairs either 1 or 3 steps at a time. Given S and C, write a function that returns the number of unique ways you can climb the staircase. The order of the steps matters.

Example:

S = 4
C = [1, 2, 3]
# Output: 
[1, 1, 1, 1], [1, 1, 2], [1, 2, 1], [1, 3], [2, 1, 1], [2, 2], [3, 1]

Solution

Access restricted

Subscribe to premium account to see the solution.

Get premium now