Longest common prefix (source code)

= Longest common prefix
{title2=$\operatorname{LCP}(s,t)$}

The longest common prefix of two <strings> is the longest <string> that is a <string prefix> of both. Its length is the number of matching initial characters before the first mismatch or the end of a <string>. A direct scan maintains equality of the processed prefixes and takes time linear in that length plus one. For suffixes represented by indices in a shared <array>, no character copying is needed.