Longest Duplicate Substring
Problem statement
You are given a lowercase string s. A duplicate substring is a non-empty contiguous substring that occurs at least twice in s. The occurrences may overlap.
Return a duplicate substring of maximum length. If several different substrings have maximum length, return the lexicographically smallest one. Return an empty string if no duplicate substring exists.
Function
longestDuplicateSubstring(s: String) → StringExamples
Example 1
s = "banana"return = "ana"ana occurs twice and no longer substring occurs at least twice.
Example 2
s = "abcd"return = ""No non-empty substring appears twice.
Example 3
s = "aaaaa"return = "aaaa"The two overlapping occurrences start at indices 0 and 1.
Constraints
2 <= s.length <= 30000.scontains only lowercase English letters.