DP

dp[i][j] = length of common substring ending at s[i], t[j]. If match: dp[i-1][j-1] + 1. Else 0. Track max.

Advertisement

Suffix array approach

Concatenate: s + '#' + t + '$'. Build SA + LCP. Max LCP between suffixes from different sides = answer.

Advertisement

Generalized suffix tree

Build for both strings. Deepest internal node with descendants from both strings = LCS.

K strings

K-string longest common substring: generalized suffix tree. Deepest internal node with descendants from all K.