Data Structures & AlgorithmsHardTCS NQT · Codeforces Div2 B

How many index pairs (i < j) of the list [1, 3, 2, 3, 4, 5, 3, 1, 2, 5] satisfy a[i] + a[j] = 6? Equal values at different positions count as different pairs.

  1. A. 3
  2. B. 8
  3. C. 18
  4. D. 9

Correct answer: D. 9

Count with a frequency map: for each value v, add freq[v] × freq[T − v] (halving the self-pairs when v = T − v). Reporting distinct value-pairs merges repeats, and that is a different count from index pairs.

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

Exams that ask this topic