Data Structures & AlgorithmsModerateTCS NQT · Infosys

How many unordered pairs of positions (i < j) in "abababcabab" have the same 2-letter substring starting there (s[i:i+2] == s[j:j+2])?

  1. A. 13
  2. B. 17
  3. C. 10
  4. D. 14

Correct answer: A. 13

Count each 2-letter block with a hash map and add c(c−1)/2 per block. Counting adjacent equal letters instead answers a different question.

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

Exams that ask this topic