Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA

From the ten numbers [3, 8, 12, 5, 7, 10, 1, 4, 9, 6], how many 3-element subsets have a sum divisible by 5?

  1. A. 24
  2. B. 27
  3. C. 23
  4. D. 9

Correct answer: A. 24

Split the numbers into two halves, enumerate the sizes and residues of their subsets mod 5, and combine matching residue classes with the total size equal to 3. Counting size-2 subsets instead is a different count.

More Coding Interview Problems questions

Exams that ask this topic