Question
The Hidden Code Strings
In an old digital archive, you discover two mysterious code strings — s1 and s2.
Somewhere inside them lies a common sequence of characters that both share exactly in the same order and without any breaks.
Your task is to uncover the length of the longest such shared sequence. In other words, the longest common substring between the two codes.
For example:
-
If
s1 = "abcjklp"ands2 = "acjkp", the secret shared code is"cjk", so the answer is3.
Input
The first line of the input contains a string representing s1.
The second line of the input contains a single string representing s2.
The second line of the input contains a single string representing s2.
Output
Print an integer representing the length of the longest common substring. If there is no common substring, the function should return 0.
Example
Input:
abcd
acdf
Output:
2
Explanation:
The longest common substring is "cd" with a length of 2.
Input:
wasdijkl
wsdjkl
Output:
3
Explanation:
The longest common substring is "jkl" with a length of 3.
abcd
acdf
Output:
2
Explanation:
The longest common substring is "cd" with a length of 2.
Input:
wasdijkl
wsdjkl
Output:
3
Explanation:
The longest common substring is "jkl" with a length of 3.