Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

How many index pairs i < j of length-2 substrings of "ababa" are equal strings?

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

Correct answer: D. 2

The four length-2 substrings are ab, ba, ab, ba; equal pairs are one pair of ab's and one pair of ba's, so the count is 2.

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

Exams that ask this topic