Data Structures & AlgorithmsModerateTCS NQT · DP warm-up

Problem: How many ways can a staircase of 8 steps be climbed if each move climbs 1, 3 or 4 steps? Run the DP below.

Problem: How many ways can a staircase of 8 steps be climbed if each move climbs 1, 3 or 4 steps? Run the DP below.
ways = [0] * 9
ways[0] = 1
for i in range(1, 9):
    for s in [1, 3, 4]:
        if i >= s:
            ways[i] += ways[i - s]
print(ways[8])
What is printed?
  1. A. 25
  2. B. 21
  3. C. 29
  4. D. 34

Correct answer: A. 25

ways[i] = ways[i-1] + ways[i-3] + ways[i-4] with ways[0] = 1 gives 1, 1, 1, 2, 4, 6, 9, 15, 25. Treating the moves as unordered sets instead of sequences is a different count.

More Coding Interview Problems questions

Exams that ask this topic