🏠 Z-Box Lighthouse

Z-Algorithm: Compute Z array to find prefix matches

📊 String & Z-Array
String:
Z[i]:
Current Index (i)
1
Z-Box [L, R]
[0, 0]
Z[i] Value
0
📋 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!