Data Structures & AlgorithmsModerateTCS NQT · Infosys

How many unordered pairs of positions of the same letter are there in "abracadabra" (i < j with s[i] = s[j])?

  1. A. 14
  2. B. 6
  3. C. 12
  4. D. 11

Correct answer: C. 12

Count each letter's occurrences c and add c(c−1)/2. Counting adjacent equal letters, or the number of repeated letters, answers different questions.

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

Exams that ask this topic