Problems > Longest Common Substring > Editorial

Longest Common Substring — Solution & Editorial

Back to the Problem

dp[i][j] = common suffix length ending at Ai, Bj: extend on match, reset to 0 otherwise (unlike LCS, no carrying over).

Complexity: O(|A|·|B|)

Watch out: Substring ≠ subsequence: the max(...) carry-over from LCS must NOT be here.