Data Structures & AlgorithmsHardTCS NQT · ICPC regional

Problem: How many subsets of {1, 2, ..., 8} contain no two consecutive integers (the empty set counts)?

  1. A. 34
  2. B. 55
  3. C. 89
  4. D. 54

Correct answer: B. 55

f(n) = f(n − 1) + f(n − 2) (n is either excluded, or included with n − 1 excluded), f(0) = 1, f(1) = 2, so f(8) = F(10) = 55. An index shift gives 34 or 89, and leaving out the empty set gives 54.

More Coding Interview Problems questions

Exams that ask this topic