Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D

Problem: The Z-array of "aaabaab" is computed (z[0] is the full length by convention). What is the sum of z[1] through z[6]?

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

Correct answer: A. 6

Z-values for "aaabaab" are [–, 2, 1, 0, 2, 1, 0], so z[1..6] sums to 6. Including z[0] = 7 gives 13, counting non-zero entries gives 4, and not stopping at the first mismatch gives 11.

More Coding Interview Problems questions

Exams that ask this topic