Z Algorithm function

The Z-function for a string S of length N is an array of length N where the i th element is equal to the greatest number of characters starting from the position i that coincide with the first characters of S.

This is a companion discussion topic for the original entry at http://iq.opengenus.org/z-algorithm-function/