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

Lists L1 = {1, 4, 7}, L2 = {2, 5, 8} and L3 = {3, 6, 9}. Choosing one element from each list, how many choices give a total of 15?

  1. A. 7
  2. B. 8
  3. C. 6
  4. D. 17

Correct answer: A. 7

Combine the first two lists into a counter of sums, then for each element of the third list look up the complement. The count is over choices, so each combination of indices is counted once.

More Coding Interview Problems questions

Exams that ask this topic