Longest Repeating Substring
MediumPractice library · +20 XPstringssuffix arraylcp array
Given a string S, find the length of the longest substring that appears at least twice. The two occurrences may overlap.
Input
A single line containing the string S.
Output
A single integer representing the length of the longest repeating substring.
Constraints
1 <= |S| <= 200000
Time limit 2 s (native code; slower languages get more)Memory 256 MB14 hidden tests
Example 1
Input
banana
Output
3
The longest repeating substring is 'ana' with length 3.
Example 2
Input
aaaaa
Output
4
The longest repeating substring is 'aaaa' with length 4.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
Example 1 input
banana
Example 2 input
aaaaa