Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

How many distinct value-pairs (x, y) with x <= y occur as a[i] + a[j] = 5 for some indices i < j in [1, 1, 2, 2, 3, 3, 4, 5]?

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

Correct answer: D. 2

Deduplicate by value: count distinct value pairs, not index pairs. Index pairs (the last option) repeat values such as (1, 4) and (2, 3) many times.

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

Exams that ask this topic