Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

How many index pairs i < j satisfy a[i] + a[j] = 10 for a = [7, 1, 5, 3, 9, 2, 8, 4, 6, 0]?

  1. A. 5
  2. B. 3
  3. C. 8
  4. D. 4

Correct answer: D. 4

A double loop with i < j counts each unordered pair once. Counting ordered pairs (i and j swapped) doubles the answer, a common off-by-one in pair counting.

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

Exams that ask this topic