Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 D

What is the length of the longest proper border of "abacabacabab"? A border is a non-empty proper prefix that is also a suffix.

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

Correct answer: A. 2

A border of length b means the prefix and suffix of length b match. The KMP prefix function at the last index gives the longest proper border directly; the smallest period is the complementary quantity n minus the border.

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

Exams that ask this topic