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

Array a = [2, 7, -3, 5, 11, 4, 9, -1, 6]. How many index pairs (i, j) with i < j have a[i] + a[j] = 10?

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

Correct answer: A. 2

Each unordered pair of positions is counted once. Counting ordered pairs doubles the answer, and counting i <= j adds self-pairs, which matter only when 2x = 10 with a repeated lookup; here the rule is simply one count per index pair.

More Coding Interview Problems questions

Exams that ask this topic