Z-function
Z-function from string S - array Z, each element of which is Z[i ] is equal to the longest prefix of the substring starting at position i in the string S, which is also the prefix of the entire string Z. The value of the Z-function at position zero is usually either zero or the length of the entire string.
Difficulty
O(|S| ^ 2) or O(|S|).
Prefix function from the string
S - array
P, each element of which
P[i] is equal to the longest suffix of the substring starting from position < code>i in the string
S, which is also the suffix of the entire string
S. The value of the
P-function at position zero is usually either zero or the length of the entire string.
Difficulty
O(|S| ^ 2) or O(|S|).
Try to implement Z function and prefix function for O(|S| ^ 2) code>.