Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

A staircase has 8 steps. Each move climbs 1 or 2 steps, but you may NOT take three single-step moves in a row. How many different sequences of moves reach exactly step 8?

  1. A. 17
  2. B. 34
  3. C. 20
  4. D. 11

Correct answer: A. 17

DP with state (position, number of consecutive single steps so far, capped at 2): a single step is allowed only when the run is below 2, and a double step resets the run. Ignoring the run-length rule gives the plain Fibonacci count.

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

Exams that ask this topic