01What z[i] means
z[i] is the length of the longest common prefix of the whole string s and its suffix s[i..]. In other words: start reading at i and at 0 at the same time, and count how many characters agree.
For s = AABAAAB you get z = [0, 1, 0, 2, 3, 1, 0]. For example z[4] = 3, because s[4..6] = AAB matches the first three characters AAB. By convention z[0] = 0 (some write n).
Computing every z[i] by direct comparison is O(n²) in the worst case, for example on AAAA…A. The real algorithm reuses work and gets O(n).