Data Structures & AlgorithmsModerateTCS CodeVita · Microsoft SDE OA

A staircase is climbed with steps of size 1, 3 or 4 (order of steps matters). How many distinct ordered sequences of steps reach exactly height 10?

A staircase is climbed with steps of size 1, 3 or 4 (order of steps matters). How many distinct ordered sequences of steps reach exactly height 10?
n=10
dp=[0]*(n+1); dp[0]=1
for x in range(1,n+1):
    for s in (1,3,4):
        if x>=s: dp[x]+=dp[x-s]
print(dp[n])
What is printed?
  1. A. 28
  2. B. 8
  3. C. 64
  4. D. 274

Correct answer: C. 64

The ordered count is a DP over the last step: dp[x] = sum of dp[x-s]. Filling with the coin-style loop over steps outside gives unordered combinations, which is a different number, and dropping or changing a step size changes the recurrence entirely.

More Coding Interview Problems questions

Exams that ask this topic