Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

Starting at step 0, you climb to step 6 taking steps of 1 or 2 each time. How many distinct sequences of steps are possible?

  1. A. 14
  2. B. 12
  3. C. 13
  4. D. 64

Correct answer: C. 13

This is the Fibonacci-style recurrence dp[i] = dp[i-1] + dp[i-2], giving 13 for n = 6. The total 2^6 = 64 would count sequences that overshoot step 6.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic