Data Structures & AlgorithmsModerateGATE CS · ICPC regional

For the string aabaaabaa, what is the sum of the Z-function values Z[1] + Z[2] + ... + Z[n-1] (Z[i] is the longest common prefix of the string and its suffix starting at i)?

  1. A. 13
  2. B. 10
  3. C. 12
  4. D. 15

Correct answer: C. 12

Each Z[i] is a longest common prefix length, computed by reusing the rightmost matching box. Using prefix-function values instead of Z values gives different numbers.

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

Exams that ask this topic