Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

How many distinct value pairs (x, y) with x < y satisfy x + y = 6 among the values in [1, 2, 3, 4, 5, 5, 1]?

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

Correct answer: C. 2

Work with the set of distinct values: the pairs (1,5) and (2,4) are the distinct value pairs summing to 6. Counting index pairs (last option) repeats values such as the duplicated 1s and 5s.

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

Exams that ask this topic