Z-algorithm
hardThe Z-box remembers the last useful comparison, so most positions are answered by copying from a mirror index. Because the box's right edge never decreases, the whole thing is linear.
Worst
O(n)Space O(n)Loading the z-algorithm engine…