Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

How many ways are there to write 10 as an ordered sum of 1s and 2s (for example 2+1+1+... counts differently from 1+2+...)?

  1. A. 90
  2. B. 89
  3. C. 91
  4. D. 93

Correct answer: B. 89

The number of ordered compositions satisfies f(n) = f(n-1) + f(n-2), the Fibonacci recurrence; f(10) is 89 with f(1)=1 and f(2)=2.

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

Exams that ask this topic