Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

What is the sum of the prefix-function values pi[0] through pi[n-1] of the string abacabab?

  1. A. 10
  2. B. 9
  3. C. 11
  4. D. 13

Correct answer: B. 9

The prefix function at each index is the length of the longest proper border of the prefix ending there; compute each value with the failure link, then add.

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

Exams that ask this topic