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

Arrays A = [3, 7, 11, 15, 20] and B = [2, 6, 9, 13, 18] each hold distinct values. How many pairs (x in A, y in B) satisfy x + y = 22?

  1. A. 2
  2. B. 15
  3. C. 12
  4. D. 1

Correct answer: D. 1

Put B into a set and look up 22 - x for each x in A; each hit is one pair. Counting pairs with sum at most 22 counts far more, which is a different question.

More Coding Interview Problems questions

Exams that ask this topic