GATE Computer ScienceModerateGATE CS (PYQ pattern)

How many index pairs i < j satisfy a[i] + a[j] == 10 in the array {3, 8, 5, 2, 7, 4, 6, 1, 9, 5, 3, 7}?

  1. A. 6
  2. B. 10
  3. C. 8
  4. D. 12

Correct answer: C. 8

Count by value: (3,7): two 3s and two 7s give 4 pairs; (8,2): 1; (4,6): 1; (1,9): 1; (5,5): 1 pair from two 5s: total 8.

More Programming and Data Structures (GATE) questions

Exams that ask this topic