Problems > Longest Repeat

Longest Repeat

Difficulty: 2100 6000 ms 128 MB

strings suffix-array

Print the length of the longest substring that occurs at least TWICE in S (overlaps allowed).

Input: one line with the string S.

Output: the longest repeated-substring length (0 if none).

Constraints:

  • 1 ≤ |S| ≤ 105
  • lowercase letters

Sample Tests

Input 1
banana
Output 1
3
Input 2
abcd
Output 2
0

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.