z[i] = length of the longest substring starting at i that matches a prefix of s. Watch the box reuse make the whole array O(n).
r is stored exclusive (one past the last matching index), so the copy clamp is
z[i] = min(r - i, z[i - l]). The Z-box s[l..r-1] always equals the prefix s[0..r-l-1];
that invariant is why copying z[i−l] is valid. See junior.md and professional.md for the
correctness proof and the amortized r-pointer argument that makes this linear.