Data Structures & AlgorithmsHardProduct Company SDE · ICPC regional

Problem: What is the length of the longest proper border (a proper prefix that is also a suffix) of "abacabacaba"? A proper border is shorter than the whole string.

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

Correct answer: B. 7

The KMP prefix function ends at 7: 'abacaba' is both a prefix and a suffix of 'abacabacaba'. 3 ('aba') is only a shorter border, 11 is the whole string (not proper), and 4 is the period n − border, not the border.

More Coding Interview Problems questions

Exams that ask this topic