Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D

Problem: The Z-function of a string s is defined as z[i] = the length of the longest common prefix of s and s[i:]; z[0] is conventionally the full length. For s = "aabxaabxcaabxaabxay", count the indices i ≥ 1 with z[i] ≥ 4.

  1. A. 4
  2. B. 3
  3. C. 2
  4. D. 5

Correct answer: B. 3

Z-values are computed in linear time with a window [l, r). Counting positions where the first character matches (z[i] ≥ 1) is a much looser condition.

More Coding Interview Problems questions

Exams that ask this topic