Data Structures & AlgorithmsHardICPC regional · combinatorics

Problem: What is the sum of C(10, k) over all even k from 0 to 10? Run the code.

Problem: What is the sum of C(10, k) over all even k from 0 to 10? Run the code.
from math import comb
print(sum(comb(10, k) for k in range(0, 11, 2)))
What is printed?
  1. A. 512
  2. B. 1024
  3. C. 256
  4. D. 500

Correct answer: A. 512

Half of the 2^10 subsets have even size, so the sum is 2^9 = 512. The trap 1024 is the sum over all k.

More Coding Interview Problems questions

Exams that ask this topic