Two servers each record a compressed activity log as a string of lowercase letters. Find the length of the longest contiguous block of characters that appears, unbroken and in the same order, as a substring of both logs.
Line 1: the first log s1 (may be empty, producing a blank line).
Line 2: the second log s2 (may be empty, producing a blank line).
Both strings contain only lowercase English letters.
A single integer: the length of the longest common (contiguous) substring of s1 and s2. If the logs share no character at all, print 0.
Example 1
Input
abcdef zzcdew
Expected
3
Explanation
"cde" appears contiguously in both strings (positions 2-4 of the first, 2-4 of the second), and no longer shared block exists, so the answer is 3.
Example 2
Input
abc xyz
Expected
0
Explanation
The two strings share no character at all, so the longest common substring has length 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →