Skip to main content
Admissions guidance, study banks, and career tools — get started on Shalyam

Compute the Z-Array

For a string s, z[i] is the length of the longest common prefix of s and the suffix starting at i, with z[0] defined as the length of s. Print the Z-array in O(n).

Constraints

1 <= |s| <= 10^5 Lowercase letters

Discussion

No discussions yet.

Rewards · v2.1

Get Exclusive Insights with Every Issue

Join Shalyam Newsletter

Stay ahead in education, research, and innovation—straight to your inbox.