Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div2 B

In the array [2, 8, 5, 5, 3, 7, 5], how many index pairs i < j have a[i] + a[j] = 10?

  1. A. 5
  2. B. 6
  3. C. 7
  4. D. 9

Correct answer: A. 5

Pairs are 2 with 8, 3 with 7, and every pair of the three 5s (which give 3 pairs). Counting only distinct values misses the repeated 5s.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic