Data Structures & AlgorithmsHardTCS NQT · Product Company SDE

Problem: Find the number of ways to select a non-empty subset of {1, 2, 4, 8, 16} whose sum is a multiple of 5.

  1. A. 6
  2. B. 7
  3. C. 3
  4. D. 31

Correct answer: A. 6

All 31 subset sums 1..31 are distinct, and exactly the multiples 5, 10, 15, 20, 25, 30 appear, so 6. Including the empty set gives 7, checking only singletons and pairs gives 3, and 31 counts every subset.

More Coding Interview Problems questions

Exams that ask this topic