
You are given two strings, s1 and s2, consisting of lowercase English letters. Your task is to find the length of the longest "unique common substring".
A substring sub is considered a unique common substring if it satisfies all of the following conditions:
1) sub is a substring of s1.If no such substring exists, the answer is 0.
The first line of input contains the string s1.
The second line of input contains the string s2.
Print a single integer representing the length of the longest unique common substring.
A substring is a contiguous block of characters. For example, "app" is a substring of "apple", but "ale" is not.
abcy
zbcd
2
The common substrings are "b", "c", and "bc".
- "b": Appears once in `s1` and once in `s2`. It is a valid unique common substring of length 1.
- "c": Appears once in `s1` and once in `s2`. It is a valid unique common substring of length 1.
- "bc": Appears once in `s1` and once in `s2`. It is a valid unique common substring of length 2.
The longest among these has a length of 2.
ababa
abac
0
The longest common substring is "aba".
- "aba": Appears twice in `s1` ("ababa") and once in `s2`. Since it repeats in `s1`, it is not a *unique* common substring.
The next longest common substring is "ab".
- "ab": Appears twice in `s1` ("ababa") and once in `s2`. It also repeats in `s1`, so it is not valid.
No common substring satisfies the uniqueness criteria for both strings. Therefore, the answer is 0.
A direct approach has a time complexity around O(N*M*min(N,M)), where N and M are the lengths of the strings.
1 <= N, M <= 1000
`s1` and `s2` consist of lowercase English letters.
Time limit: 1 sec