#C9341. Longest Common Substring
Longest Common Substring
Longest Common Substring
You are given two strings S1 and S2. Your task is to compute the length of the longest common substring between them. A substring is a contiguous sequence of characters within a string. In other words, find the maximum length k such that there exists an index i in S1 and an index j in S2 where:
\( S1[i\ldots i+k-1] = S2[j\ldots j+k-1] \)
If no common substring exists, the answer is 0.
Note: Ensure your solution reads input from stdin
and writes output to stdout
.
inputFormat
The input consists of two lines. The first line contains the string S1
and the second line contains the string S2
.
outputFormat
Output a single integer denoting the length of the longest common substring between S1
and S2
.
abcdxyz
xyzabcd
4