This question evaluates proficiency in string algorithms, pattern matching, and algorithmic complexity analysis, focusing on designing efficient data structures and algorithms for finding repeated substrings.
You are given a string s consisting of lowercase English letters.
A substring of s is any contiguous sequence of characters, i.e., s[i..j) for 0 ≤ i < j ≤ len(s).
Design an algorithm to find any one of the longest substrings that appears at least twice in s. The two occurrences may overlap. If no substring appears at least twice, return the empty string.
s
of length
n
(e.g.,
1 ≤ n ≤ 2 × 10^5
).
O(n^2)
substring comparison approach.
s = "banana"
"ana"
.
s = "abcd"
""
(empty string).
Describe your algorithm, its time and space complexity, and how it scales for large n.