Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE

Problem: Count the subsets of [3, 1, 4, 2, 6, 4] whose sum is exactly half the total sum (the subset may be any size; the empty subset is counted only if the total is 0).

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

Correct answer: A. 6

The total is 20, so count subsets with sum 10 by a subset-sum DP (or 64 bitmasks): 6, the two 4s being different positions. Counting each split {S, complement} once gives 3, 64 counts every subset, and counting each subset together with its complement again gives 12.

More Coding Interview Problems questions

Exams that ask this topic