Data Structures & AlgorithmsModerateICPC regional · Amazon SDE OA

Using the standard convention z[0] = 0, what is the sum of the Z-function values z[1] through z[6] of the string "aaabaab"?

  1. A. 13
  2. B. 7
  3. C. 6
  4. D. 4

Correct answer: C. 6

Z-values are the longest common prefix of s and s[i:]. z = [0, 2, 1, 0, 2, 1, 0]: the sum over i >= 1 is 6. Setting z[0] = n inflates the total.

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

Exams that ask this topic