Longest Duplicate Substring
Given a string s, find the longest substring that occurs at least twice in s (occurrences may overlap). Return any such longest duplicated substring, or the empty string if none exists.
Open official problem prompt ↗Return the longest chunk of the string that shows up in two or more (possibly overlapping) places.
Like finding the longest musical phrase repeated in a song: guess a phrase length, fingerprint every phrase of that length, and see if any fingerprint recurs; then adjust the guessed length.
- Input
- s = "banana"
- Output
- "ana"
- Why
- "ana" appears at index 1 and index 3 and is the longest substring that repeats.
2 <= s.length <= 3 * 10^4s consists of lowercase English letters