dsa10 min read
Z Algorithm Explained — Linear Time Pattern Matching with the Z Array
The Z algorithm computes Z[i] equals the length of the longest substring starting at index i that matches a prefix of the string in linear O(n) time. Cleaner than KMP for many problems and the foundation of competitive programming string toolkits.
Read →