Introduction
Note. In this note, we use zero-based indexing. That is, the first character of a string has index , and the last character has index .
The Z-function of a string at position is the length of the longest prefix of the substring starting at position that is also a prefix of the whole string .
