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+...)?
- A. 90
- B. 89
- C. 91
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- What is the multiplicative order of 2 modulo 17 (the smallest k > 0 with 2^k ≡ 1 mod 17)?
- How many integers x in [1, 100] can be written as a^2 + b^2 with positive integers a and b?
- What is 2^100 mod 7?
- Every element of the circular array [1, 2, 3, 4] is replaced by the sum of its two circular neighbours, taken modulo 10, simultaneously…
- How many pairs a < b with 1 <= a < b <= 12 satisfy gcd(a, b) = b - a?
- How many integers n in [1, 60] satisfy n^2 - n divisible by 6?