Data Structures & AlgorithmsHardGATE CS · TCS NQT

How many indices i in "xyzxyzxyz" satisfy s[i] = s[i + 3]?

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

Correct answer: B. 6

A period-3 string matches itself at shift 3 everywhere the shift fits, so the count is length minus 3. The shift of 2 (the second option) has no matches here.

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

Exams that ask this topic