Data Structures & AlgorithmsVery hardTCS NQT · Infosys

How many index pairs i < j in the array [1, 3, 1, 2, 3, 3] have a[i] = a[j]?

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

Correct answer: D. 4

For each value with frequency f there are f(f-1)/2 equal pairs. The value 3 occurs three times, giving three pairs by itself.

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

Exams that ask this topic