🏠 Z-Box Lighthouse
Z-Algorithm: Compute Z array to find prefix matches
Build Z Array
📊 String & Z-Array
String:
Z[i]:
Current Index (i)
1
Z-Box [L, R]
[0, 0]
Z[i] Value
0
Reset
Step
Auto Build
📋 Z-Array Log
💡 Understanding Z[i]
Z[i]
= length of the longest substring starting at position i that matches a prefix of the string.
The
Z-box [L, R]
represents the rightmost segment that matches a prefix. We use this to skip redundant comparisons!