Data Structures & AlgorithmsHardICPC regional · Codeforces Div2 C

Problem: The smallest period of a string s is the least p ≥ 1 such that s[i] = s[i+p] for all valid i. What is the smallest period of "abcabcabcab"?

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

Correct answer: A. 3

Check each shift p from 1 upward for full agreement. The length of the longest border gives n minus this period, so confusing the two is a common slip.

More Coding Interview Problems questions

Exams that ask this topic