Data Structures & AlgorithmsHardTCS NQT · Accenture

In the array [1, 5, 5, 5, 5, 5, 5, 5, 5, 9], how many distinct value pairs {x, y} with x <= y satisfy x + y = 10, where x and y both occur in the array (a value may pair with itself only if it occurs at least twice)?

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

Correct answer: A. 2

The unordered value pairs are {1, 9} and {5, 5}; the second needs two copies of 5, which the array has. Counting index pairs instead would give a much larger number.

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

Exams that ask this topic