Data Structures & AlgorithmsHardGATE CS · ICPC regional

How many subsets of {1, 2, ..., 7} have a sum exactly equal to half of 1 + 2 + ... + 7? (The complementary subset is counted separately.)

  1. A. 4
  2. B. 12
  3. C. 64
  4. D. 8

Correct answer: D. 8

Count with a bitmask over the elements (or a subset-sum DP); each valid subset pairs with its complement, so the answer is even. Dividing by 2 gives the unordered count of splits, which is a different quantity.

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

Exams that ask this topic