Z-array computation
Your task
Given a lowercase string s, compute its Z-array and return it as a list, where z[0] is defined as 0 and z[i] (i>0) is the length of the longest substring starting at i that matches a prefix of s. For 'aabxaab' return [0,1,0,0,3,1,0]. Length up to a few thousand.
Examples
z_array(s: str) -> list[int]Example 1
Input
z_array("aabxaab")Output
[0, 1, 0, 0, 3, 1, 0]