Data Structures & AlgorithmsHardGATE CS · ICPC regional

What is the smallest positive period p of the string abcabcabca, meaning the smallest p such that s[i] = s[i+p] for every valid i?

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

Correct answer: A. 3

The smallest period is n minus the longest proper border, and the prefix function gives that border in linear time. For this string the border is the length-7 prefix.

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

Exams that ask this topic