Data Structures & AlgorithmsVery hardTCS NQT · Accenture

How many pairs of distinct positions (i, j) with i < j in the string abcdcba satisfy s[i] = s[j]?

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

Correct answer: A. 3

Each letter with frequency f gives f(f-1)/2 pairs: a and b appear twice each, c twice, and d once.

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

Exams that ask this topic