Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA

Sorted array a = [2, 3, 5, 6, 8, 10]. How many DISTINCT values appear among the sums a[i] + a[j] over pairs i < j?

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

Correct answer: A. 12

There are 15 index pairs, but some sums coincide, so the answer is the number of distinct values among them. Put every pairwise sum into a set and take its size; counting index pairs gives 15 and ignores repeated sums.

More Coding Interview Problems questions

Exams that ask this topic