LCP Array
Use inverse suffix ranks and Kasai reuse to compute adjacent longest common prefixes in linear time.
Core idea
Kasai's algorithm visits suffixes in text order. If one suffix shares h characters with its suffix-array predecessor, the next text suffix can reuse at least h minus one before extending comparisons.
Read the visualization
The suffix-array rank selects the comparison neighbor. A highlighted prefix shows reused characters, then grows only while new characters match.
Build inverse suffix ranks and initialize the reusable prefix length to zero.
Complexity and tradeoffs
Time: O(n). Space: O(n). The reused prefix length decreases by at most one per text position, bounding total comparisons.
Where it fits
Together with a suffix array, LCP values reveal repeated substrings and support range-minimum queries for arbitrary suffix-prefix lengths.