Problems > Longest Common Substring

Longest Common Substring

Difficulty: 1600 2000 ms 128 MB

strings dp

Print the length of the longest CONTIGUOUS string appearing in both A and B.

Input: two lines: string A, then string B.

Output: the longest common substring length (0 if none).

Constraints:

  • 1 ≤ |A|, |B| ≤ 500
  • lowercase letters

Sample Tests

Input 1
abcdxyz
xyzabcd
Output 1
4
Input 2
abc
def
Output 2
0

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.