Data Structures & AlgorithmsHardGATE CS
How many subsets of {1, 2, ..., 15} (including the empty set) contain no two consecutive integers and have an even sum?
- A. 792
- B. 798
- C. 805
- D. 820
Correct answer: C. 805
There are 1597 subsets with no two consecutive integers (Fibonacci F17), and enumeration shows 805 of them have an even sum; the empty set counts. The remaining 792 have odd sum, so the split is not exactly even.
More Coding Interview Problems questions
- How many integers n with 1 <= n <= 100000 are divisible by exactly one of the numbers 6, 10 and 15?
- How many primes p < 500 have p - 2 or p + 2 also prime (that is, belong to at least one twin-prime pair, counted as individual primes)?
- 0/1 knapsack with capacity 27: weights [13, 8, 9, 14, 12, 4, 11] and values [25, 19, 16, 27, 22, 8, 23] (item i has weight w[i] and value…
- How many structurally distinct binary trees with 8 nodes have at most 4 levels (a single root alone is 1 level)?
- How many binary strings of length 12 contain neither 101 nor 010 as a substring?
- What are the last three digits of 7^2025?