In this algorithm, we build a z-array that contains for each index i the length of the longest substring starting from i which is also a prefix of S where S is a given string.
For example, the z-array of ACBACDACBACBACDA is as follows:
Z-Algo can be used for pattern searching with O(n) time complexity.