#C6766. Longest Common Substring

    ID: 50562 Type: Default 1000ms 256MiB

Longest Common Substring

Longest Common Substring

You are given two strings, s and k. Your task is to compute the length of the longest common substring between these two strings. A substring is a contiguous sequence of characters within a string.

The solution can be approached using dynamic programming. In particular, you can define a DP table (dp[i][j]) such that if (s[i-1] = k[j-1]), then (dp[i][j] = dp[i-1][j-1] + 1); otherwise, (dp[i][j] = 0). The final answer is the maximum value in this table.

inputFormat

The input is read from standard input. It consists of two lines. The first line contains the string s and the second line contains the string k.

outputFormat

Output a single integer to standard output representing the length of the longest common substring between the two given strings.## sample

abcdef
zcdemf
3